home / github / issues

Menu
  • Search all tables
  • GraphQL API

issues: 894669073

This data as json

id node_id number title user state locked assignee milestone comments created_at updated_at closed_at author_association active_lock_reason draft pull_request body reactions performed_via_github_app state_reason repo type
894669073 MDU6SXNzdWU4OTQ2NjkwNzM= 5333 Unexpected behaviour of pcolormesh with logscale in x or y axes 11541317 closed 0     1 2021-05-18T18:39:12Z 2021-07-02T12:42:35Z 2021-07-02T12:42:35Z CONTRIBUTOR      

What happened:

When using xarray.DataArray.plot.pcolormesh with yscale="log" the output figure distorts the y axis and thus doesn't plot the data correctly. I think the problem is related to the inference of the intervals through the xarray.plot.utils._infer_intervals_breaks() function.

What you expected to happen:

I expect the yscale="log" argument to correctly display the y axis in a logscale while precisley plotting the data. In my opinion, the inference of the intervals for the pcolormesh should be also done in log scales.

Minimal Complete Verifiable Example:

```python import numpy as np import xarray as xr import matplotlib.pyplot as plt

x = np.linspace(-3, 4, 15) y = np.logspace(-4, 3, 8)

xx, yy = np.meshgrid(x, y) z = np.exp(-(xx ** 2) - np.log10(yy) ** 2) - np.exp( -((xx - 1) ** 2) - (np.log10(yy) - 1) ** 2 )

da = xr.DataArray( z, coords={"x": x, "y": y}, dims=("y", "x"), )

da.plot(yscale="log") plt.show()

```

Output:

Anything else we need to know?:

I pass infer_intervals=False I get a plot that looks more to the expected one:

```python import numpy as np import xarray as xr import matplotlib.pyplot as plt

x = np.linspace(-3, 4, 15) y = np.logspace(-4, 3, 8)

xx, yy = np.meshgrid(x, y) z = np.exp(-(xx ** 2) - np.log10(yy) ** 2) - np.exp( -((xx - 1) ** 2) - (np.log10(yy) - 1) ** 2 )

da = xr.DataArray( z, coords={"x": x, "y": y}, dims=("y", "x"), )

da.plot(yscale="log", infer_intervals=False) plt.show()

```

The problem with deactivating the infer_intervals is that matplotlib crops the last row and column of the 2d grid, because we would be selectingshading="flat", getting the following deprecation warning from matplotlib: /home/santi/git/xarray/xarray/plot/plot.py:1033: MatplotlibDeprecationWarning: shading='flat' when X and Y have the same dimensions as C is deprecated since 3.3. Either specify the corners of the quadrilaterals with X and Y, or pass shading='auto', 'nearest' or 'gouraud', or set rcParams['pcolor.shading']. This will become an error two minor releases later. primitive = ax.pcolormesh(x, y, z, **kwargs)

That's why I think that the inference of the breaks should also be done in log scales.

Environment:

Output of <tt>xr.show_versions()</tt> INSTALLED VERSIONS ------------------ commit: 49aa235fc63706dc145128dd13fdf139b9d5bc6e python: 3.9.4 | packaged by conda-forge | (default, May 10 2021, 22:13:33) [GCC 9.3.0] python-bits: 64 OS: Linux OS-release: 5.12.1-2-MANJARO machine: x86_64 processor: byteorder: little LC_ALL: None LANG: en_US.utf8 LOCALE: ('en_US', 'UTF-8') libhdf5: 1.10.6 libnetcdf: 4.7.4 xarray: 0.18.1.dev33+g49aa235f pandas: 1.2.4 numpy: 1.20.1 scipy: 1.6.3 netCDF4: 1.5.6 pydap: installed h5netcdf: 0.11.0 h5py: 3.2.1 Nio: None zarr: 2.8.1 cftime: 1.4.1 nc_time_axis: 1.2.0 PseudoNetCDF: installed rasterio: 1.2.3 cfgrib: 0.9.9.0 iris: 2.4.0 bottleneck: 1.3.2 dask: 2021.05.0 distributed: 2021.05.0 matplotlib: 3.4.2 cartopy: 0.19.0.post1 seaborn: 0.11.1 numbagg: installed pint: 0.17 setuptools: 49.6.0.post20210108 pip: 21.1.1 conda: None pytest: 6.2.4 IPython: None sphinx: None
{
    "url": "https://api.github.com/repos/pydata/xarray/issues/5333/reactions",
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  completed 13221727 issue

Links from other tables

  • 2 rows from issues_id in issues_labels
  • 1 row from issue in issue_comments
Powered by Datasette · Queries took 1.913ms · About: xarray-datasette