html_url,issue_url,id,node_id,user,created_at,updated_at,author_association,body,reactions,performed_via_github_app,issue https://github.com/pydata/xarray/issues/6629#issuecomment-1134878042,https://api.github.com/repos/pydata/xarray/issues/6629,1134878042,IC_kwDOAMm_X85DpN1a,6872529,2022-05-23T16:18:21Z,2022-05-23T16:18:21Z,NONE,Sure @dcherian . I have no objection to that. Is there an easy way of doing that or should I copy paste everything from here to there?,"{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,1244977848 https://github.com/pydata/xarray/issues/6629#issuecomment-1134554277,https://api.github.com/repos/pydata/xarray/issues/6629,1134554277,IC_kwDOAMm_X85Dn-yl,6872529,2022-05-23T11:28:47Z,2022-05-23T11:28:47Z,NONE,"I can confirm that after implementing these changes in my local xarray package, everything works es expected. I added a check on each dimension/coordinate to make sure it is of datetime dtype before making any changes. Starting on line https://github.com/pydata/xarray/blob/4da7fdbd85bb82e338ad65a532dd7a9707e18ce0/xarray/plot/plot.py#L1316 I now have: ```python @_plot2d def imshow(x, y, z, ax, **kwargs): """""" Image plot of 2D DataArray. Wraps :py:func:`matplotlib:matplotlib.pyplot.imshow`. While other plot methods require the DataArray to be strictly two-dimensional, ``imshow`` also accepts a 3D array where some dimension can be interpreted as RGB or RGBA color channels and allows this dimension to be specified via the kwarg ``rgb=``. Unlike :py:func:`matplotlib:matplotlib.pyplot.imshow`, which ignores ``vmin``/``vmax`` for RGB(A) data, xarray *will* use ``vmin`` and ``vmax`` for RGB(A) data by applying a single scaling factor and offset to all bands. Passing ``robust=True`` infers ``vmin`` and ``vmax`` :ref:`in the usual way `. .. note:: This function needs uniformly spaced coordinates to properly label the axes. Call :py:meth:`DataArray.plot` to check. The pixels are centered on the coordinates. For example, if the coordinate value is 3.2, then the pixels for those coordinates will be centered on 3.2. """""" if x.ndim != 1 or y.ndim != 1: raise ValueError( ""imshow requires 1D coordinates, try using pcolormesh or contour(f)"" ) def _center_pixels(x): """"""Center the pixels on the coordinates."""""" if np.issubdtype(x.dtype, str): # When using strings as inputs imshow converts it to # integers. Choose extent values which puts the indices in # in the center of the pixels: return 0 - 0.5, len(x) - 0.5 # vvvvvv added vvvvvv elif np.issubdtype(x.dtype, np.datetime64): from matplotlib.dates import date2num x = date2num(x) # ^^^^^^ added ^^^^^^ try: # Center the pixels assuming uniform spacing: xstep = 0.5 * (x[1] - x[0]) except IndexError: # Arbitrary default value, similar to matplotlib behaviour: xstep = 0.1 return x[0] - xstep, x[-1] + xstep # Center the pixels: left, right = _center_pixels(x) top, bottom = _center_pixels(y) defaults = {""origin"": ""upper"", ""interpolation"": ""nearest""} if not hasattr(ax, ""projection""): # not for cartopy geoaxes defaults[""aspect""] = ""auto"" # Allow user to override these defaults defaults.update(kwargs) if defaults[""origin""] == ""upper"": defaults[""extent""] = [left, right, bottom, top] else: defaults[""extent""] = [left, right, top, bottom] if z.ndim == 3: # matplotlib imshow uses black for missing data, but Xarray makes # missing data transparent. We therefore add an alpha channel if # there isn't one, and set it to transparent where data is masked. if z.shape[-1] == 3: alpha = np.ma.ones(z.shape[:2] + (1,), dtype=z.dtype) if np.issubdtype(z.dtype, np.integer): alpha *= 255 z = np.ma.concatenate((z, alpha), axis=2) else: z = z.copy() z[np.any(z.mask, axis=-1), -1] = 0 primitive = ax.imshow(z, **defaults) # If x or y are strings the ticklabels have been replaced with # integer indices. Replace them back to strings: for axis, v in [(""x"", x), (""y"", y)]: if np.issubdtype(v.dtype, str): getattr(ax, f""set_{axis}ticks"")(np.arange(len(v))) getattr(ax, f""set_{axis}ticklabels"")(v) # vvvvvv added vvvvvv elif np.issubdtype(v.dtype, np.datetime64): getattr(ax, f""{axis}axis_date"")() # ^^^^^^ added ^^^^^^ return primitive ```","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,1244977848