You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When creating a quiver plot of an xarray Dataset using ds.plot.quiver, there are empty spots in the wrong places. This problem only seems to occur when a hue array is given to quiver and the data is masked, i.e., there are NaN values in the array. The empty spots are not only in the masked locations, but seem to appear in arbitrary locations.
What did you expect to happen?
Plotting the same data with the matplotlib function plt.quiver, the empty spots are not there, no matter if there is a hue (called color in matplotlib) or NaN values. This is the result I expected, and I expect that the xarray plot method gives the same result.
Minimal Complete Verifiable Example
importxarrayasxrimportmatplotlib.pyplotaspltds=xr.Dataset(coords={"x": range(20), "y": range(15)})
ds["c"] =xr.ones_like(xr.broadcast(ds.y, ds.x)[0])
# Mask out the central band# When the next line is commented out, the problem does not occurds["c"] =ds.c.where((ds.x-10)**2>1)
fig, axs=plt.subplots(2, 2, sharex=True, sharey=True)
# Plot the data with the xarray methodds.plot.quiver("x", "y", "c", "c", add_guide=False, ax=axs[0, 0]) # this works as expectedds.plot.quiver("x", "y", "c", "c", "c", add_guide=False, ax=axs[0, 1]) # this does not# Make the same plot directly with matplotlib to see the expected resultaxs[1, 0].quiver(ds.x, ds.y, ds.c, ds.c) # this works as expectedaxs[1, 1].quiver(ds.x, ds.y, ds.c, ds.c, ds.c) # this works, tooaxs[0, 0].set_title("xarray plot, no hue")
axs[0, 1].set_title("xarray plot, with hue")
axs[1, 0].set_title("manual plot, no color")
axs[1, 1].set_title("manual plot, with color")
foraxinaxs.flatten():
ax.set(xlabel="", ylabel="")
plt.show()
MVCE confirmation
Minimal example — the example is as focused as reasonably possible to demonstrate the underlying issue in xarray.
Complete example — the example is self-contained, including all data and the text of any traceback.
Verifiable example — the example copy & pastes into an IPython prompt or Binder notebook, returning the result.
New issue — a search of GitHub Issues suggests this is not a duplicate.
Recent environment — the issue occurs with the latest version of xarray and its dependencies.
Relevant log output
No response
Anything else we need to know?
This is the figure that is created with the example code. The problems are the empty spots in the top right panel. I expected this panel to look like the bottom right panel.
The left column shows that there are no problems when there is no hue/color argument. The quiver plot created with xarray looks just like the one created manually with matplotlib.
Thanks for opening your first issue here at xarray! Be sure to follow the issue template!
If you have an idea for a solution, we would really welcome a Pull Request with proposed changes.
See the Contributing Guide for more.
It may take us a while to respond here, but we really value your contribution. Contributors like you help make xarray better.
Thank you!
What happened?
When creating a quiver plot of an xarray Dataset using
ds.plot.quiver
, there are empty spots in the wrong places. This problem only seems to occur when ahue
array is given toquiver
and the data is masked, i.e., there areNaN
values in the array. The empty spots are not only in the masked locations, but seem to appear in arbitrary locations.What did you expect to happen?
Plotting the same data with the matplotlib function
plt.quiver
, the empty spots are not there, no matter if there is ahue
(calledcolor
in matplotlib) orNaN
values. This is the result I expected, and I expect that the xarray plot method gives the same result.Minimal Complete Verifiable Example
MVCE confirmation
Relevant log output
No response
Anything else we need to know?
This is the figure that is created with the example code. The problems are the empty spots in the top right panel. I expected this panel to look like the bottom right panel.
The left column shows that there are no problems when there is no hue/color argument. The quiver plot created with xarray looks just like the one created manually with matplotlib.
Environment
INSTALLED VERSIONS
commit: None
python: 3.8.10 (default, Nov 22 2023, 10:22:35)
[GCC 9.4.0]
python-bits: 64
OS: Linux
OS-release: 5.4.0-174-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_GB.UTF-8
LOCALE: ('en_GB', 'UTF-8')
libhdf5: 1.12.0
libnetcdf: 4.7.4
xarray: 2022.12.0
pandas: 1.3.0
numpy: 1.23.5
scipy: 1.9.3
netCDF4: 1.5.8
pydap: None
h5netcdf: 0.7.1
h5py: 2.10.0
Nio: None
zarr: 2.11.3
cftime: 1.5.2
nc_time_axis: None
PseudoNetCDF: None
rasterio: None
cfgrib: 0.9.10.1
iris: None
bottleneck: 1.2.1
dask: 2022.05.0
distributed: None
matplotlib: 3.6.2
cartopy: 0.21.1
seaborn: 0.13.0
numbagg: None
fsspec: 2022.3.0
cupy: None
pint: None
sparse: None
flox: None
numpy_groupies: None
setuptools: 45.2.0
pip: 23.2.1
conda: None
pytest: 4.6.9
mypy: None
IPython: 8.12.3
sphinx: 3.5.3
The text was updated successfully, but these errors were encountered: