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

plt.pcolormesh will infer interval breaks per default #4364

Open
mathause opened this issue Aug 21, 2020 · 3 comments
Open

plt.pcolormesh will infer interval breaks per default #4364

mathause opened this issue Aug 21, 2020 · 3 comments

Comments

@mathause
Copy link
Collaborator

mathause commented Aug 21, 2020

Looking at some warnings in #3266 I saw that matplotlib will deprecate the old behaviour of pcolormesh when the shape of the data and the coordinates are equal (they silently cut a row and a column of the data). With the new behaviour they will interpolate the coordinates.

import numpy as np
import matplotlib.pyplot as plt

x = np.array([1, 2, 3])
y = np.array([1, 2, 3, 4, 5])

data = np.random.randn(*y.shape + x.shape)

f, axes = plt.subplots(1, 2)

for ax, shading, behavior in zip(axes, ["flat", "nearest"], ["old", "new"]):
  ax.pcolormesh(x, y, data, shading=shading, vmin=-0.75, vmax=0.75)
  ax.set_title(f"{behavior}: shading='{shading}'")

shading_old_new

This is a good thing in general - we already do this for a long time with the infer_intervals keyword. Unfortunately they don't check if the data is monotonic (matplotlib/matplotlib#18317) which can lead to problems for maps (SciTools/cartopy#1638). I don't think there is a need to do something right now - let's see what they think upstream.

This change was introduced in mpl 3.3.0

@leroyvn
Copy link

leroyvn commented Jan 13, 2021

I have a similar issue with nonmonotonic coordinates (mapping a 2D image to a zenith-azimuth space). Solving this is easy when using Matplotlib's API directly, since I can compute mesh coordinates by myself (on a array with one row and one column more) and supply these as pcolormesh()'s x and y arguments; but I can't inject these into xarray's pcolormesh() function. Wouldn't allowing infer_interval=False and passing ordinary arrays as x and y be a good solution?

@fmaussion
Copy link
Member

Another consequence is that this example in the docs is now meaningless / misleading. I've just come across the series of discussions in cartopy about this issue - it looks quite complex and I'm also not sure yet what to do in xarray in the mean time.

Wouldn't allowing infer_interval=False and passing ordinary arrays as x and y be a good solution?

I'm not sure what you mean by that? You can always set infer_interval=False at the xarray level?

@leroyvn
Copy link

leroyvn commented Mar 19, 2021

I'm not sure what you mean by that? You can always set infer_interval=False at the xarray level?

Yes indeed, but you cannot pass custom Numpy arrays as the x and y parameters to set.

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

4 participants