pydata / pydata/xarray

plt.pcolormesh will infer interval breaks per default

Open
#4,364 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

topic-plotting
Dominant language
Python
Stars
4.2k
Forks
1.4k
Avg merge
2d 15h
Merged PRs (30d)
14

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the pcolormesh behavior introduced in matplotlib 3.3.0 and the upstream discussion in matplotlib/matplotlib#18317. Compare that behavior with xarray's existing infer_intervals handling and the map-related concern in scitools/cartopy#1638; the issue does not name a file, test, or specific change, so completion depends on deciding what upstream behavior xarray should support.

Written by the indexing model from the issue text.

Assessment

Tech stack
matplotlib, numpy, python
Domain
data-visualization
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.