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

Skip to content

Commit 46343dc

Browse files
authored
Merge pull request #20180 from meeseeksmachine/auto-backport-of-pr-19876-on-v3.4.x
Backport PR #19876 on branch v3.4.x (FIX: re-order unit conversion and mask array coercion)
2 parents 09dfa2e + 1dee4a6 commit 46343dc

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5651,9 +5651,10 @@ def _pcolorargs(self, funcname, *args, shading='flat', **kwargs):
56515651
if len(args) == 3:
56525652
# Check x and y for bad data...
56535653
C = np.asanyarray(args[2])
5654-
X, Y = [cbook.safe_masked_invalid(a) for a in args[:2]]
56555654
# unit conversion allows e.g. datetime objects as axis values
5655+
X, Y = args[:2]
56565656
X, Y = self._process_unit_info([("x", X), ("y", Y)], kwargs)
5657+
X, Y = [cbook.safe_masked_invalid(a) for a in [X, Y]]
56575658

56585659
if funcname == 'pcolormesh':
56595660
if np.ma.is_masked(X) or np.ma.is_masked(Y):

lib/matplotlib/tests/test_axes.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1637,6 +1637,36 @@ def test_boxplot_dates_pandas(pd):
16371637
plt.boxplot(data, positions=years)
16381638

16391639

1640+
def test_pcolor_regression(pd):
1641+
from pandas.plotting import (
1642+
register_matplotlib_converters,
1643+
deregister_matplotlib_converters,
1644+
)
1645+
1646+
fig = plt.figure()
1647+
ax = fig.add_subplot(111)
1648+
1649+
times = [datetime.datetime(2021, 1, 1)]
1650+
while len(times) < 7:
1651+
times.append(times[-1] + datetime.timedelta(seconds=120))
1652+
1653+
y_vals = np.arange(5)
1654+
1655+
time_axis, y_axis = np.meshgrid(times, y_vals)
1656+
shape = (len(y_vals) - 1, len(times) - 1)
1657+
z_data = np.arange(shape[0] * shape[1])
1658+
1659+
z_data.shape = shape
1660+
try:
1661+
register_matplotlib_converters()
1662+
1663+
im = ax.pcolormesh(time_axis, y_axis, z_data)
1664+
# make sure this does not raise!
1665+
fig.canvas.draw()
1666+
finally:
1667+
deregister_matplotlib_converters()
1668+
1669+
16401670
def test_bar_pandas(pd):
16411671
# Smoke test for pandas
16421672
df = pd.DataFrame(

0 commit comments

Comments
 (0)