Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Backport PR #19876 on branch v3.4.x (FIX: re-order unit conversion and mask array coercion) #20180

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5651,9 +5651,10 @@ def _pcolorargs(self, funcname, *args, shading='flat', **kwargs):
if len(args) == 3:
# Check x and y for bad data...
C = np.asanyarray(args[2])
X, Y = [cbook.safe_masked_invalid(a) for a in args[:2]]
# unit conversion allows e.g. datetime objects as axis values
X, Y = args[:2]
X, Y = self._process_unit_info([("x", X), ("y", Y)], kwargs)
X, Y = [cbook.safe_masked_invalid(a) for a in [X, Y]]

if funcname == 'pcolormesh':
if np.ma.is_masked(X) or np.ma.is_masked(Y):
Expand Down
30 changes: 30 additions & 0 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1637,6 +1637,36 @@ def test_boxplot_dates_pandas(pd):
plt.boxplot(data, positions=years)


def test_pcolor_regression(pd):
from pandas.plotting import (
register_matplotlib_converters,
deregister_matplotlib_converters,
)

fig = plt.figure()
ax = fig.add_subplot(111)

times = [datetime.datetime(2021, 1, 1)]
while len(times) < 7:
times.append(times[-1] + datetime.timedelta(seconds=120))

y_vals = np.arange(5)

time_axis, y_axis = np.meshgrid(times, y_vals)
shape = (len(y_vals) - 1, len(times) - 1)
z_data = np.arange(shape[0] * shape[1])

z_data.shape = shape
try:
register_matplotlib_converters()

im = ax.pcolormesh(time_axis, y_axis, z_data)
# make sure this does not raise!
fig.canvas.draw()
finally:
deregister_matplotlib_converters()


def test_bar_pandas(pd):
# Smoke test for pandas
df = pd.DataFrame(
Expand Down