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

Contour with vmin/ vmax differs from matplotlib #3744

Open
mathause opened this issue Feb 3, 2020 · 0 comments
Open

Contour with vmin/ vmax differs from matplotlib #3744

mathause opened this issue Feb 3, 2020 · 0 comments

Comments

@mathause
Copy link
Collaborator

mathause commented Feb 3, 2020

MCVE Code Sample

import numpy as np
import xarray as xr
import matplotlib as mpl
import matplotlib.pyplot as plt

data = xr.DataArray(np.arange(24).reshape(4, 6))

data.plot.contour(vmax=10, add_colorbar=True)

contour_xarray

Expected Output

h = plt.contour(data.values, vmax=10)
plt.colorbar(h)

contour_matplotlib

Problem Description

A contour(vmax=vmax) plot differs between xarray and matplotlib. I think the problem is here:

levels = np.linspace(vmin, vmax, levels)

xarray calculates the levels from vmax while matplotlib (probably) calculates the levels from data.max() and uses vmax only for the norm. For contourf and pcolormesh this is not so relevant as the capped values are then drawn with the over color. However, there may also be a good reason for this behavior.

Output of xr.show_versions()

INSTALLED VERSIONS

commit: 4c96d53
python: 3.7.6 | packaged by conda-forge | (default, Jan 7 2020, 22:33:48)
[GCC 7.3.0]
python-bits: 64
OS: Linux
OS-release: 4.12.14-lp151.28.36-default
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_GB.UTF-8
LOCALE: en_US.UTF-8
libhdf5: 1.10.5
libnetcdf: 4.6.2

xarray: 999 (master)
pandas: 0.25.3
numpy: 1.17.3
scipy: 1.4.1
netCDF4: 1.5.1.2
pydap: installed
h5netcdf: 0.7.4
h5py: 2.10.0
Nio: 1.5.5
zarr: 2.4.0
cftime: 1.0.4.2
nc_time_axis: 1.2.0
PseudoNetCDF: installed
rasterio: 1.1.0
cfgrib: 0.9.7.6
iris: 2.2.0
bottleneck: 1.3.1
dask: 2.9.2
distributed: 2.9.2
matplotlib: 3.1.2
cartopy: 0.17.0
seaborn: 0.9.0
numbagg: installed
setuptools: 45.0.0.post20200113
pip: 19.3.1
conda: None
pytest: 5.3.3
IPython: 7.11.1
sphinx: None

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

No branches or pull requests

2 participants