Thanks to visit codestin.com
Credit goes to github.com

Skip to content

pcolormesh x-axis with datetime broken for nearest shading #18547

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

Closed
fthyssen opened this issue Sep 23, 2020 · 1 comment · Fixed by #18549
Closed

pcolormesh x-axis with datetime broken for nearest shading #18547

fthyssen opened this issue Sep 23, 2020 · 1 comment · Fixed by #18549
Milestone

Comments

@fthyssen
Copy link

Bug report

Bug summary

When using a datetime x-axis in a pcolormesh, and nearest shading,

TypeError: '>=' not supported between instances of 'datetime.timedelta' and 'int'

is raised.

From what I can tell, #18398 assumed comparison with 0 would always be possible, but this isn't the case for datetime.timedelta.

Code for reproduction

from datetime import datetime

from matplotlib import pyplot as plt

x_coords = [datetime.fromtimestamp(x * 3600) for x in range(24)]
y_coords = [*range(0, 10)]
plt.pcolormesh(x_coords,
               y_coords, [[*range(24)] for _ in range(10)],
               shading="nearest")

Actual outcome

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File ".local/lib/python3.8/site-packages/matplotlib/pyplot.py", line 2801, in pcolormesh
    __ret = gca().pcolormesh(
  File ".local/lib/python3.8/site-packages/matplotlib/__init__.py", line 1438, in inner
    return func(ax, *map(sanitize_sequence, args), **kwargs)
  File ".local/lib/python3.8/site-packages/matplotlib/axes/_axes.py", line 6093, in pcolormesh
    X, Y, C, shading = self._pcolorargs('pcolormesh', *args,
  File ".local/lib/python3.8/site-packages/matplotlib/axes/_axes.py", line 5651, in _pcolorargs
    X = _interp_grid(X)
  File ".local/lib/python3.8/site-packages/matplotlib/axes/_axes.py", line 5633, in _interp_grid
    if not (np.all(dX >= 0) or np.all(dX <= 0)):
TypeError: '>=' not supported between instances of 'datetime.timedelta' and 'int'

Expected outcome

None

Matplotlib version

  • Matplotlib version: 3.3.2
  • Python version: 3.8

works with pip3 install matplotlib==3.3.1, fails with pip3 install matplotlib==3.3.2

@jklymak
Copy link
Member

jklymak commented Sep 23, 2020

Thanks, though I don't think this never "worked", just an oversight that unit conversion needs to happen sooner. See fix in new PR...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants