Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Matplotlib scatterplot does not work with pandas timestamp/datetime format #9939

Closed
BlackArbsCEO opened this issue Dec 5, 2017 · 5 comments

Comments

Projects
None yet
3 participants
@BlackArbsCEO
Copy link

commented Dec 5, 2017

Bug report

Bug summary

Matplotlib version 2.1 scatter plot with pandas.DatetimeIndex or numpy.array of pandas._libs.tslib.Timestamp values as x-axis generates TypeError: invalid type promotion.

Code for reproduction

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

fake_dates = pd.date_range('2013','2014', freq='W')
# fake_dates = pd.date_range('2013,'2014', freq='W').values # same error
fake_data = np.random.randn(len(fake_dates))

fig, ax = plt.subplots()
ax.scatter(fake_dates, fake_data)

Actual outcome

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-54-a98e1d058705> in <module>()
      1 fig, ax = plt.subplots()
----> 2 ax.scatter(fake_dates, fake_data)

~/anaconda3/envs/bayesian/lib/python3.6/site-packages/matplotlib/__init__.py in inner(ax, *args, **kwargs)
   1708                     warnings.warn(msg % (label_namer, func.__name__),
   1709                                   RuntimeWarning, stacklevel=2)
-> 1710             return func(ax, *args, **kwargs)
   1711         pre_doc = inner.__doc__
   1712         if pre_doc is None:

~/anaconda3/envs/bayesian/lib/python3.6/site-packages/matplotlib/axes/_axes.py in scatter(self, x, y, s, c, marker, cmap, norm, vmin, vmax, alpha, linewidths, verts, edgecolors, **kwargs)
   4085             linewidths = rcParams['lines.linewidth']
   4086 
-> 4087         offsets = np.column_stack([x, y])
   4088 
   4089         collection = mcoll.PathCollection(

~/anaconda3/envs/bayesian/lib/python3.6/site-packages/numpy/lib/shape_base.py in column_stack(tup)
    351             arr = array(arr, copy=False, subok=True, ndmin=2).T
    352         arrays.append(arr)
--> 353     return _nx.concatenate(arrays, 1)
    354 
    355 def dstack(tup):

TypeError: invalid type promotion

Expected outcome

Should output scatter plot with dates on x axis and values on y axis. I'm not sure which prior version this worked on but it did work.

Matplotlib version

  • Operating system:
  • Matplotlib version:
  • Matplotlib backend: module://ipykernel.pylab.backend_inline
  • Python version:
  • Jupyter version (if applicable):
  • Other libraries:
    image
@afvincent

This comment has been minimized.

Copy link
Contributor

commented Dec 5, 2017

@BlackArbsCEO Thank you for opening the ticket :).

By any chance, would you have the possibility to test the master branch from GitHub? I just tested your snippet in an IPython shell and everything seems to run fine. The issue may already have been fixed in the development version.

@jklymak

This comment has been minimized.

Copy link
Contributor

commented Dec 5, 2017

See #9771. Pandas no longer registers their converter...

@BlackArbsCEO

This comment has been minimized.

Copy link
Author

commented Dec 5, 2017

@afvincent Is there a pip install git+https:\\matplotlib-dev-version.git command for installing the development version?

@jklymak thanks for the link. I tried registering the converter using the suggestion and it worked. Appreciate it.

@jklymak

This comment has been minimized.

Copy link
Contributor

commented Dec 5, 2017

Yeah, its a pandas 0.21 issue, not us...

@jklymak jklymak closed this Dec 5, 2017

@afvincent

This comment has been minimized.

Copy link
Contributor

commented Dec 5, 2017

@BlackArbsCEO I may be one of the last person on Earth to ask for advices when it comes to questions related to git (or pip by the way) 🐑. Personally I am just able to follow the Matplotlib dedicated documentation... I was asking in case you already had the development version installed somewhere: please, do not bother and mess your current installation of Matplotlib if it is an issue on Pandas' side (as it seems to be) :).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.