Closed
Description
da.plot.pcolormesh
, where da
is a DataArray
, fails with TypeError: invalid type promotion
when one of the coordinates is a datetime array:
$ cat mwe.py
#!/usr/bin/env python3.6
import xarray
import numpy
da = xarray.DataArray(
numpy.arange(3*4).reshape(3,4),
dims=("x", "y"),
coords={"x": [1,2,3],
"y": [numpy.datetime64(f"2000-01-{x:02d}")
for x in range(1, 5)]})
da.plot.pcolormesh()
$ ./mwe.py
Traceback (most recent call last):
File "./mwe.py", line 13, in <module>
da.plot.pcolormesh()
File "/dev/shm/gerrit/venv/stable-3.6/lib/python3.6/site-packages/xarray/plot/plot.py", line 547, in plotmethod
return newplotfunc(**allargs)
File "/dev/shm/gerrit/venv/stable-3.6/lib/python3.6/site-packages/xarray/plot/plot.py", line 500, in newplotfunc
**kwargs)
File "/dev/shm/gerrit/venv/stable-3.6/lib/python3.6/site-packages/xarray/plot/plot.py", line 667, in pcolormesh
primitive = ax.pcolormesh(x, y, z, **kwargs)
File "/dev/shm/gerrit/venv/stable-3.6/lib/python3.6/site-packages/matplotlib/__init__.py", line 1710, in inner
return func(ax, *args, **kwargs)
File "/dev/shm/gerrit/venv/stable-3.6/lib/python3.6/site-packages/matplotlib/axes/_axes.py", line 5636, in pcolormesh
coords = np.column_stack((X, Y)).astype(float, copy=False)
File "/dev/shm/gerrit/venv/stable-3.6/lib/python3.6/site-packages/numpy/lib/shape_base.py", line 353, in column_stack
return _nx.concatenate(arrays, 1)
TypeError: invalid type promotion