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

Skip to content

Commit 788abaf

Browse files
tacaswellMeeseeksDev[bot]
authored and
MeeseeksDev[bot]
committed
Backport PR #9168: Fix pcolormesh and DatetimeIndex error
<!--Thank you so much for your PR! To help us review, fill out the form to the best of your ability. Please make use of the development guide at https://matplotlib.org/devdocs/devel/index.html--> <!--Provide a general summary of your changes in the title above, for example "Raises ValueError on Non-Numeric Input to set_xlim". Please avoid non-descriptive titles such as "Addresses issue 8576".--> <!--If you are able to do so, please do not create the PR out of master, but out of a separate branch. See https://matplotlib.org/devel/gitwash/development_workflow.html for instructions.--> PR Summary Fixes issue with `DatetimeIndex` and `pcolormesh`: #9167 <!--Please provide at least 1-2 sentences describing the pull request in detail. Why is this change required? What problem does it solve?--> <!--If it fixes an open issue, please link to the issue here.--> PR Checklist - [X ] Code is PEP 8 compliant <!--We understand that PRs can sometimes be overwhelming, especially as the reviews start coming in. Please let us know if the reviews are unclear or the recommended next step seems overly demanding , or if you would like help in addressing a reviewer's comments. And please ping us if you've been waiting too long to hear back on your PR.-->
1 parent f5893ce commit 788abaf

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5620,15 +5620,16 @@ def pcolormesh(self, *args, **kwargs):
56205620

56215621
X, Y, C = self._pcolorargs('pcolormesh', *args, allmatch=allmatch)
56225622
Ny, Nx = X.shape
5623-
5623+
X = X.ravel()
5624+
Y = Y.ravel()
56245625
# unit conversion allows e.g. datetime objects as axis values
56255626
self._process_unit_info(xdata=X, ydata=Y, kwargs=kwargs)
56265627
X = self.convert_xunits(X)
56275628
Y = self.convert_yunits(Y)
56285629

56295630
# convert to one dimensional arrays
56305631
C = C.ravel()
5631-
coords = np.column_stack((X.flat, Y.flat)).astype(float, copy=False)
5632+
coords = np.column_stack((X, Y)).astype(float, copy=False)
56325633

56335634
collection = mcoll.QuadMesh(Nx - 1, Ny - 1, coords,
56345635
antialiased=antialiased, shading=shading,

lib/matplotlib/tests/test_axes.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4929,6 +4929,17 @@ def test_broken_barh_empty():
49294929
ax.broken_barh([], (.1, .5))
49304930

49314931

4932+
def test_pandas_pcolormesh():
4933+
pd = pytest.importorskip('pandas')
4934+
4935+
time = pd.date_range('2000-01-01', periods=10)
4936+
depth = np.arange(20)
4937+
data = np.random.rand(20, 10)
4938+
4939+
fig, ax = plt.subplots()
4940+
ax.pcolormesh(time, depth, data)
4941+
4942+
49324943
def test_pandas_indexing_dates():
49334944
pd = pytest.importorskip('pandas')
49344945

0 commit comments

Comments
 (0)