home / github

Menu
  • Search all tables
  • GraphQL API

issue_comments

Table actions
  • GraphQL API for issue_comments

4 rows where issue = 1244977848 sorted by updated_at descending

✎ View and edit SQL

This data as json, CSV (advanced)

Suggested facets: reactions, created_at (date), updated_at (date)

user 3

  • shaharkadmiel 2
  • jklymak 1
  • dcherian 1

author_association 3

  • NONE 2
  • CONTRIBUTOR 1
  • MEMBER 1

issue 1

  • `plot.imshow` with datetime coordinate fails · 4 ✖
id html_url issue_url node_id user created_at updated_at ▲ author_association body reactions performed_via_github_app issue
1137286712 https://github.com/pydata/xarray/issues/6629#issuecomment-1137286712 https://api.github.com/repos/pydata/xarray/issues/6629 IC_kwDOAMm_X85DyZ44 jklymak 1562854 2022-05-25T14:02:13Z 2022-05-25T14:02:13Z CONTRIBUTOR

See also https://github.com/pydata/xarray/issues/1435 and https://github.com/matplotlib/matplotlib/issues/22105

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  `plot.imshow` with datetime coordinate fails 1244977848
1134878042 https://github.com/pydata/xarray/issues/6629#issuecomment-1134878042 https://api.github.com/repos/pydata/xarray/issues/6629 IC_kwDOAMm_X85DpN1a shaharkadmiel 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
}
  `plot.imshow` with datetime coordinate fails 1244977848
1134743567 https://github.com/pydata/xarray/issues/6629#issuecomment-1134743567 https://api.github.com/repos/pydata/xarray/issues/6629 IC_kwDOAMm_X85DotAP dcherian 2448579 2022-05-23T14:22:29Z 2022-05-23T14:22:29Z MEMBER

Thanks @shaharkadmiel . Can we instead push this logic upstream to matplotlib? That way a lot more people would benefit

{
    "total_count": 2,
    "+1": 2,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  `plot.imshow` with datetime coordinate fails 1244977848
1134554277 https://github.com/pydata/xarray/issues/6629#issuecomment-1134554277 https://api.github.com/repos/pydata/xarray/issues/6629 IC_kwDOAMm_X85Dn-yl shaharkadmiel 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 <robust-plotting>`.

.. 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
}
  `plot.imshow` with datetime coordinate fails 1244977848

Advanced export

JSON shape: default, array, newline-delimited, object

CSV options:

CREATE TABLE [issue_comments] (
   [html_url] TEXT,
   [issue_url] TEXT,
   [id] INTEGER PRIMARY KEY,
   [node_id] TEXT,
   [user] INTEGER REFERENCES [users]([id]),
   [created_at] TEXT,
   [updated_at] TEXT,
   [author_association] TEXT,
   [body] TEXT,
   [reactions] TEXT,
   [performed_via_github_app] TEXT,
   [issue] INTEGER REFERENCES [issues]([id])
);
CREATE INDEX [idx_issue_comments_issue]
    ON [issue_comments] ([issue]);
CREATE INDEX [idx_issue_comments_user]
    ON [issue_comments] ([user]);
Powered by Datasette · Queries took 1519.963ms · About: xarray-datasette