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

Skip to content

Commit b43e6c7

Browse files
committed
Fix bivariate handling with pcolormesh
1 parent 1508bf1 commit b43e6c7

File tree

3 files changed

+15
-13
lines changed

3 files changed

+15
-13
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5182,8 +5182,9 @@ def _pcolorargs(funcname, *args, **kw):
51825182
cmap = mcolors.BivariateColormap()
51835183
if norm is None:
51845184
norm = mcolors.BivariateNorm()
5185-
C = norm(C)
5186-
numRows, numCols = C.shape
5185+
numRows, numCols = C.shape[1:]
5186+
else:
5187+
numRows, numCols = C.shape
51875188
if allmatch:
51885189
X, Y = np.meshgrid(np.arange(numCols), np.arange(numRows))
51895190
else:
@@ -5201,8 +5202,9 @@ def _pcolorargs(funcname, *args, **kw):
52015202
cmap = mcolors.BivariateColormap()
52025203
if norm is None:
52035204
norm = mcolors.BivariateNorm()
5204-
C = norm(C)
5205-
numRows, numCols = C.shape
5205+
numRows, numCols = C.shape[1:]
5206+
else:
5207+
numRows, numCols = C.shape
52065208
else:
52075209
raise TypeError(
52085210
'Illegal arguments to %s; see help(%s)' % (funcname, funcname))
@@ -5599,25 +5601,25 @@ def pcolormesh(self, *args, **kwargs):
55995601
X, Y, C = self._pcolorargs('pcolormesh', *args, **kw)
56005602
Ny, Nx = X.shape
56015603

5602-
if (isinstance(norm, mcolors.BivariateNorm) or
5603-
isinstance(cmap, mcolors.BivariateColormap)):
5604-
norm = mcolors.NoNorm()
5605-
56065604
# unit conversion allows e.g. datetime objects as axis values
56075605
self._process_unit_info(xdata=X, ydata=Y, kwargs=kwargs)
56085606
X = self.convert_xunits(X)
56095607
Y = self.convert_yunits(Y)
56105608

5611-
# convert to one dimensional arrays
5612-
C = C.ravel()
5609+
# convert to one dimensional arrays if univariate
5610+
if isinstance(norm, mcolors.BivariateNorm):
5611+
C = np.asarray([C[0].ravel(), C[1].ravel()])
5612+
else:
5613+
C = C.ravel()
5614+
56135615
coords = np.column_stack((X.flat, Y.flat)).astype(float, copy=False)
56145616

56155617
collection = mcoll.QuadMesh(Nx - 1, Ny - 1, coords,
56165618
antialiased=antialiased, shading=shading,
56175619
**kwargs)
56185620
collection.set_alpha(alpha)
56195621
collection.set_array(C)
5620-
if norm is not None and not isinstance(norm, mcolors.Normalize):
5622+
if norm is not None and not isinstance(norm, mcolors.Norms):
56215623
msg = "'norm' must be an instance of 'mcolors.Normalize'"
56225624
raise ValueError(msg)
56235625
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 not isinstance(self.norm, colors.BivariateNorm):
242242
if x.shape[2] == 3:
243243
if alpha is None:
244244
alpha = 1

lib/matplotlib/collections.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,7 @@ def update_scalarmappable(self):
730730
"""
731731
if self._A is None:
732732
return
733-
if self._A.ndim > 1:
733+
if self._A.ndim > 1 and not isinstance(self.norm, mcolors.BivariateNorm):
734734
raise ValueError('Collections can only map rank 1 arrays')
735735
if not self.check_update("array"):
736736
return

0 commit comments

Comments
 (0)