Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong facet plots when all 2D arrays have one value only #3734

Closed
malmans2 opened this issue Jan 31, 2020 · 1 comment · Fixed by #3916
Closed

Wrong facet plots when all 2D arrays have one value only #3734

malmans2 opened this issue Jan 31, 2020 · 1 comment · Fixed by #3916

Comments

@malmans2
Copy link
Contributor

MCVE Code Sample

import xarray as xr
import numpy as np
# Create DataArray
da = xr.DataArray(np.zeros((10, 10, 4)))
# Default plot
# Wrong: all of them should be 0.
da.plot(col='dim_2')
<xarray.plot.facetgrid.FacetGrid at 0x7f511815f3d0>

output_2_1

Expected Output

# Providing colorbar limits
# Correct.
da.plot(col='dim_2', vmin=-.1, vmax=.1)
<xarray.plot.facetgrid.FacetGrid at 0x7f50ef14bf70>

output_3_1

Problem Description

If I simply use plot triggering FacetGrid to show 2D arrays which all have the same value (zero in the example above), all plots with exception of the last one are wrong. However, if I specify vmin and vmax using the same limits of the default plot, all plots are correct.

Output of xr.show_versions()

INSTALLED VERSIONS
------------------
commit: None
python: 3.8.1 | packaged by conda-forge | (default, Jan 29 2020, 14:55:04) 
[GCC 7.3.0]
python-bits: 64
OS: Linux
OS-release: 4.4.0-133-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8
libhdf5: 1.10.5
libnetcdf: 4.7.3

xarray: 0.14.1
pandas: 1.0.0
numpy: 1.17.5
scipy: None
netCDF4: 1.5.3
pydap: None
h5netcdf: None
h5py: None
Nio: None
zarr: None
cftime: 1.0.4.2
nc_time_axis: None
PseudoNetCDF: None
rasterio: None
cfgrib: None
iris: None
bottleneck: 1.3.1
dask: 2.10.1
distributed: 2.10.0
matplotlib: 3.1.2
cartopy: None
seaborn: None
numbagg: None
setuptools: 45.1.0.post20200119
pip: 20.0.2
conda: None
pytest: None
IPython: 7.11.1
sphinx: None
@malmans2
Copy link
Contributor Author

malmans2 commented Feb 1, 2020

This fixes the problem:

plot_data = da.values
kwargs = xr.plot.utils._determine_cmap_params(plot_data)
if kwargs['vmin'] == kwargs['vmax']:
    kwargs['vmin'] -= .1
    kwargs['vmax'] += .1
da.plot(col='dim_2', **kwargs)

Does it make sense to add the following somewhere in _determine_cmap_params?

if vmin == vmax:
    vmin -= .1
    vmax += .1

dcherian added a commit to dcherian/xarray that referenced this issue Mar 29, 2020
dcherian added a commit to dcherian/xarray that referenced this issue Mar 29, 2020
dcherian added a commit that referenced this issue Apr 3, 2020
* facetgrid: fix case when vmin == vmax

Fixes #3734

* minor fix.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants