Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Description
Bug summary
As of Dec. 11 2023,Axes.pcolorfast()
seems to not work withdatetime
; see#27450 for more details.
Code for reproduction
importnumpyasnpimportmatplotlib.pyplotaspltimportmatplotlib.datesasdtimportmatplotlibasmplimportdatetimenp.random.seed(19680801)'''Directly inputting datetime.datetime without processing them seems to generate compile errors for pcolorfast().I have used date2num() to ensure that the graph prints correctly despite that such operations may defy the purpose of conducting such tests.'''basedate_x=datetime.datetime(2023,12,6,1,30,30)basedate_y=datetime.datetime(2024,5,5,12,15,45)dates_x= [(basedate_x+datetime.timedelta(days=1*i,hours=6*i,minutes=20*i,seconds=0))foriinrange(10)]dates_y= [(basedate_y+datetime.timedelta(days=1*i,hours=8*i,minutes=30*i,seconds=0))foriinrange(10)]data=np.random.rand(0,100)fig,ax=plt.subplots()pc=ax.pcolorfast(dates_x,dates_y,data)ax.set_xlabel('Sample datetime')ax.set_ylabel('Sample data')ax.set_title('Sample test case for pcolorfast()')plt.show()
Actual outcome
Traceback (most recent call last):
File "personal directory omitted", line 23, in
pc = ax.pcolorfast(dates_x, dates_y, data)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\andyx\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\matplotlib_init_.py", line 1478, in inner
return func(ax, *map(sanitize_sequence, args), **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\andyx\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\matplotlib\axes_axes.py", line 6501, in pcolorfast
self.update_datalim(np.array([[xl, yb], [xr, yt]]))
File "C:\Users\andyx\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\matplotlib\axes_base.py", line 2510, in update_datalim
if not np.any(np.isfinite(xys)):
^^^^^^^^^^^^^^^^
TypeError: ufunc 'isfinite' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''
Expected outcome
It has been assumed that a graph should be produced similar to the one below, but with actualdatetime
as axes:
Additional information
This is part of a test case for issue#26864 ; same issue has been met when the same code is ran on matplotlib ver 3.7.1 on Google Colab.
Operating system
Windows 10
Matplotlib Version
3.8.2
Matplotlib Backend
No response
Python version
3.11.7
Jupyter version
No response
Installation
pip