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

Skip to content

Commit 8f6928d

Browse files
committed
Fix bivariate handling with pcolormesh
1 parent 8a985f0 commit 8f6928d

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5200,8 +5200,9 @@ def _pcolorargs(funcname, *args, **kw):
52005200
cmap = mcolors.BivariateColormap()
52015201
if norm is None:
52025202
norm = mcolors.BivariateNorm()
5203-
C = norm(C)
5204-
numRows, numCols = C.shape
5203+
numRows, numCols = C.shape[1:]
5204+
else:
5205+
numRows, numCols = C.shape
52055206
if allmatch:
52065207
X, Y = np.meshgrid(np.arange(numCols), np.arange(numRows))
52075208
else:
@@ -5219,8 +5220,9 @@ def _pcolorargs(funcname, *args, **kw):
52195220
cmap = mcolors.BivariateColormap()
52205221
if norm is None:
52215222
norm = mcolors.BivariateNorm()
5222-
C = norm(C)
5223-
numRows, numCols = C.shape
5223+
numRows, numCols = C.shape[1:]
5224+
else:
5225+
numRows, numCols = C.shape
52245226
else:
52255227
raise TypeError(
52265228
'Illegal arguments to %s; see help(%s)' % (funcname, funcname))
@@ -5614,25 +5616,25 @@ def pcolormesh(self, *args, **kwargs):
56145616
X, Y, C = self._pcolorargs('pcolormesh', *args, **kw)
56155617
Ny, Nx = X.shape
56165618

5617-
if (isinstance(norm, mcolors.BivariateNorm) or
5618-
isinstance(cmap, mcolors.BivariateColormap)):
5619-
norm = mcolors.NoNorm()
5620-
56215619
# unit conversion allows e.g. datetime objects as axis values
56225620
self._process_unit_info(xdata=X, ydata=Y, kwargs=kwargs)
56235621
X = self.convert_xunits(X)
56245622
Y = self.convert_yunits(Y)
56255623

5626-
# convert to one dimensional arrays
5627-
C = C.ravel()
5624+
# convert to one dimensional arrays if univariate
5625+
if isinstance(norm, mcolors.BivariateNorm):
5626+
C = np.asarray([C[0].ravel(), C[1].ravel()])
5627+
else:
5628+
C = C.ravel()
5629+
56285630
coords = np.column_stack((X.flat, Y.flat)).astype(float, copy=False)
56295631

56305632
collection = mcoll.QuadMesh(Nx - 1, Ny - 1, coords,
56315633
antialiased=antialiased, shading=shading,
56325634
**kwargs)
56335635
collection.set_alpha(alpha)
56345636
collection.set_array(C)
5635-
if norm is not None and not isinstance(norm, mcolors.Normalize):
5637+
if norm is not None and not isinstance(norm, mcolors.Norms):
56365638
msg = "'norm' must be an instance of 'mcolors.Normalize'"
56375639
raise ValueError(msg)
56385640
collection.set_cmap(cmap)

lib/matplotlib/cm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ def to_rgba(self, x, alpha=None, bytes=False, norm=True):
238238
"""
239239
# First check for special case, image input:
240240
try:
241-
if x.ndim == 3:
241+
if x.ndim == 3 and (x.shape[-1] == 3 or x.shape[-1] == 4):
242242
if x.shape[2] == 3:
243243
if alpha is None:
244244
alpha = 1

lib/matplotlib/collections.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,8 @@ def update_scalarmappable(self):
731731
"""
732732
if self._A is None:
733733
return
734-
if self._A.ndim > 1:
734+
if (self._A.ndim > 1 and
735+
not isinstance(self.norm, mcolors.BivariateNorm)):
735736
raise ValueError('Collections can only map rank 1 arrays')
736737
if not self.check_update("array"):
737738
return

0 commit comments

Comments
 (0)