Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3edd176

Browse filesBrowse files
tacaswelljklymak
authored andcommitted
Merge pull request #18549 from jklymak/fix-pcolorarg-convert-before-interp
FIX: unit-convert pcolorargs before interpolating
1 parent c18921a commit 3edd176
Copy full SHA for 3edd176

File tree

Expand file treeCollapse file tree

2 files changed

+24
-13
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+24
-13
lines changed

‎lib/matplotlib/axes/_axes.py

Copy file name to clipboardExpand all lines: lib/matplotlib/axes/_axes.py
+8-13Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5535,8 +5535,7 @@ def imshow(self, X, cmap=None, norm=None, aspect=None,
55355535
self.add_image(im)
55365536
return im
55375537

5538-
@staticmethod
5539-
def _pcolorargs(funcname, *args, shading='flat'):
5538+
def _pcolorargs(self, funcname, *args, shading='flat', **kwargs):
55405539
# - create X and Y if not present;
55415540
# - reshape X and Y as needed if they are 1-D;
55425541
# - check for proper sizes based on `shading` kwarg;
@@ -5567,6 +5566,10 @@ def _pcolorargs(funcname, *args, shading='flat'):
55675566
# Check x and y for bad data...
55685567
C = np.asanyarray(args[2])
55695568
X, Y = [cbook.safe_masked_invalid(a) for a in args[:2]]
5569+
# unit conversion allows e.g. datetime objects as axis values
5570+
self._process_unit_info(xdata=X, ydata=Y, kwargs=kwargs)
5571+
X = self.convert_xunits(X)
5572+
Y = self.convert_yunits(Y)
55705573
if funcname == 'pcolormesh':
55715574
if np.ma.is_masked(X) or np.ma.is_masked(Y):
55725575
raise ValueError(
@@ -5815,14 +5818,10 @@ def pcolor(self, *args, shading=None, alpha=None, norm=None, cmap=None,
58155818
if shading is None:
58165819
shading = rcParams['pcolor.shading']
58175820
shading = shading.lower()
5818-
X, Y, C, shading = self._pcolorargs('pcolor', *args, shading=shading)
5821+
X, Y, C, shading = self._pcolorargs('pcolor', *args, shading=shading,
5822+
kwargs=kwargs)
58195823
Ny, Nx = X.shape
58205824

5821-
# unit conversion allows e.g. datetime objects as axis values
5822-
self._process_unit_info(xdata=X, ydata=Y, kwargs=kwargs)
5823-
X = self.convert_xunits(X)
5824-
Y = self.convert_yunits(Y)
5825-
58265825
# convert to MA, if necessary.
58275826
C = ma.asarray(C)
58285827
X = ma.asarray(X)
@@ -6091,14 +6090,10 @@ def pcolormesh(self, *args, alpha=None, norm=None, cmap=None, vmin=None,
60916090
kwargs.setdefault('edgecolors', 'None')
60926091

60936092
X, Y, C, shading = self._pcolorargs('pcolormesh', *args,
6094-
shading=shading)
6093+
shading=shading, kwargs=kwargs)
60956094
Ny, Nx = X.shape
60966095
X = X.ravel()
60976096
Y = Y.ravel()
6098-
# unit conversion allows e.g. datetime objects as axis values
6099-
self._process_unit_info(xdata=X, ydata=Y, kwargs=kwargs)
6100-
X = self.convert_xunits(X)
6101-
Y = self.convert_yunits(Y)
61026097

61036098
# convert to one dimensional arrays
61046099
C = C.ravel()

‎lib/matplotlib/tests/test_axes.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_axes.py
+16Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,6 +1188,22 @@ def test_pcolornearest(fig_test, fig_ref):
11881188
ax.pcolormesh(x2, y2, Z, shading='nearest')
11891189

11901190

1191+
@check_figures_equal(extensions=["png"])
1192+
def test_pcolornearestunits(fig_test, fig_ref):
1193+
ax = fig_test.subplots()
1194+
x = [datetime.datetime.fromtimestamp(x * 3600) for x in range(10)]
1195+
y = np.arange(0, 3)
1196+
np.random.seed(19680801)
1197+
Z = np.random.randn(2, 9)
1198+
ax.pcolormesh(x, y, Z, shading='flat')
1199+
1200+
ax = fig_ref.subplots()
1201+
# specify the centers
1202+
x2 = [datetime.datetime.fromtimestamp((x + 0.5) * 3600) for x in range(9)]
1203+
y2 = y[:-1] + np.diff(y) / 2
1204+
ax.pcolormesh(x2, y2, Z, shading='nearest')
1205+
1206+
11911207
@check_figures_equal(extensions=["png"])
11921208
def test_pcolordropdata(fig_test, fig_ref):
11931209
ax = fig_test.subplots()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.