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

Skip to content

Commit f98978f

Browse files
committed
Update is_bivar condition to expect either BivariateNorm or BivariateColormap
1 parent 59f56af commit f98978f

File tree

3 files changed

+26
-14
lines changed

3 files changed

+26
-14
lines changed

examples/images_contours_and_fields/bivariate_demo.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828

2929
bivariate = [air_temp, surf_pres]
3030

31+
# to distinguish bivariate data either BivariateNorm or BivariateColormap must
32+
# be passed in as argument
3133
cax = ax.imshow(bivariate, norm=colors.BivariateNorm(),
3234
cmap=colors.BivariateColormap())
3335

lib/matplotlib/axes/_axes.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5151,8 +5151,11 @@ def imshow(self, X, cmap=None, norm=None, aspect=None,
51515151
raise ValueError(msg)
51525152

51535153
temp = np.asarray(X)
5154-
is_bivari = (temp.ndim == 3 or temp.shape[0] == 2)
5154+
is_bivari = (isinstance(norm, mcolors.BivariateNorm) or
5155+
isinstance(cmap, mcolors.BivariateColormap))
51555156
if is_bivari:
5157+
if temp.ndim != 3 and temp.shape[0] != 2:
5158+
raise TypeError("Expected shape like (2, n, m)")
51565159
if cmap is None:
51575160
cmap = mcolors.BivariateColormap()
51585161
if norm is None:
@@ -5205,7 +5208,8 @@ def _pcolorargs(funcname, *args, **kw):
52055208

52065209
if len(args) == 1:
52075210
C = np.asanyarray(args[0])
5208-
is_bivari = (C.ndim == 3 or C.shape[0] == 2)
5211+
is_bivari = (isinstance(norm, mcolors.BivariateNorm) or
5212+
isinstance(cmap, mcolors.BivariateColormap))
52095213
if is_bivari:
52105214
numRows, numCols = C.shape[1:]
52115215
else:
@@ -5220,12 +5224,9 @@ def _pcolorargs(funcname, *args, **kw):
52205224

52215225
if len(args) == 3:
52225226
X, Y, C = [np.asanyarray(a) for a in args]
5223-
is_bivari = (C.ndim == 3 or C.shape[0] == 2)
5227+
is_bivari = (isinstance(norm, mcolors.BivariateNorm) or
5228+
isinstance(cmap, mcolors.BivariateColormap))
52245229
if is_bivari:
5225-
if cmap is None:
5226-
cmap = mcolors.BivariateColormap()
5227-
if norm is None:
5228-
norm = mcolors.BivariateNorm()
52295230
numRows, numCols = C.shape[1:]
52305231
else:
52315232
numRows, numCols = C.shape
@@ -5414,8 +5415,11 @@ def pcolor(self, *args, **kwargs):
54145415
X, Y, C = self._pcolorargs('pcolor', *args, **kw)
54155416
Ny, Nx = X.shape
54165417

5417-
is_bivari = (C.ndim == 3 or C.shape[0] == 2)
5418+
is_bivari = (isinstance(norm, mcolors.BivariateNorm) or
5419+
isinstance(cmap, mcolors.BivariateColormap))
54185420
if is_bivari:
5421+
if C.ndim != 3 and C.shape[0] != 2:
5422+
raise TypeError("Expected shape like (2, n, m)")
54195423
if cmap is None:
54205424
cmap = mcolors.BivariateColormap()
54215425
if norm is None:
@@ -5638,8 +5642,11 @@ def pcolormesh(self, *args, **kwargs):
56385642
X, Y, C = self._pcolorargs('pcolormesh', *args, **kw)
56395643
Ny, Nx = X.shape
56405644

5641-
is_bivari = (C.ndim == 3 or C.shape[0] == 2)
5645+
is_bivari = (isinstance(norm, mcolors.BivariateNorm) or
5646+
isinstance(cmap, mcolors.BivariateColormap))
56425647
if is_bivari:
5648+
if C.ndim != 3 and C.shape[0] != 2:
5649+
raise TypeError("Expected shape like (2, n, m)")
56435650
if cmap is None:
56445651
cmap = mcolors.BivariateColormap()
56455652
if norm is None:
@@ -5798,8 +5805,11 @@ def pcolorfast(self, *args, **kwargs):
57985805

57995806
C = np.asarray(args[-1])
58005807

5801-
is_bivari = (C.ndim == 3 or C.shape[0] == 2)
5808+
is_bivari = (isinstance(norm, mcolors.BivariateNorm) or
5809+
isinstance(cmap, mcolors.BivariateColormap))
58025810
if is_bivari:
5811+
if C.ndim != 3 and C.shape[0] != 2:
5812+
raise TypeError("Expected shape like (2, n, m)")
58035813
if cmap is None:
58045814
cmap = mcolors.BivariateColormap()
58055815
if norm is None:

lib/matplotlib/tests/test_axes.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5285,17 +5285,17 @@ def test_bivariates():
52855285
bivariate = [air_temp, surf_pres]
52865286

52875287
fig1, ax1 = plt.subplots()
5288-
cax1 = ax1.imshow(bivariate)
5288+
cax1 = ax1.imshow(bivariate, norm=mcolors.BivariateNorm())
52895289
cbar = fig1.colorbar(cax1, xlabel='air_temp', ylabel='surf_pres')
52905290

52915291
fig2, ax2 = plt.subplots()
5292-
cax2 = ax2.pcolor(bivariate)
5292+
cax2 = ax2.pcolor(bivariate, norm=mcolors.BivariateNorm())
52935293
cbar = fig2.colorbar(cax2, xlabel='air_temp', ylabel='surf_pres')
52945294

52955295
fig3, ax3 = plt.subplots()
5296-
cax3 = ax3.pcolormesh(bivariate)
5296+
cax3 = ax3.pcolormesh(bivariate, norm=mcolors.BivariateNorm())
52975297
cbar = fig3.colorbar(cax3, xlabel='air_temp', ylabel='surf_pres')
52985298

52995299
fig4, ax4 = plt.subplots()
5300-
cax4 = ax4.pcolorfast(bivariate)
5300+
cax4 = ax4.pcolorfast(bivariate, norm=mcolors.BivariateNorm())
53015301
cbar = fig4.colorbar(cax4, xlabel='air_temp', ylabel='surf_pres')

0 commit comments

Comments
 (0)