@@ -5141,12 +5141,30 @@ def imshow(self, X, cmap=None, norm=None, aspect=None,
5141
5141
if not self ._hold :
5142
5142
self .cla ()
5143
5143
5144
- if norm is not None and not isinstance (norm , mcolors .Normalize ):
5145
- msg = "'norm' must be an instance of 'mcolors.Normalize'"
5144
+ isNorm = isinstance (norm , (mcolors .Normalize , mcolors .BivariateNorm ))
5145
+ if norm is not None and not isNorm :
5146
+ msg = "'norm' must be an instance of 'mcolors.Normalize' " \
5147
+ "or 'mcolors.BivariateNorm'"
5146
5148
raise ValueError (msg )
5149
+
5147
5150
if aspect is None :
5148
5151
aspect = rcParams ['image.aspect' ]
5149
5152
self .set_aspect (aspect )
5153
+
5154
+ temp = np .asarray (X )
5155
+ if (temp .ndim == 3 and isinstance (norm , mcolors .BivariateNorm ) or
5156
+ isinstance (cmap , mcolors .BivariateColormap )):
5157
+ if cmap is None :
5158
+ cmap = mcolors .BivariateColormap ()
5159
+ if norm is None :
5160
+ norm = mcolors .BivariateNorm ()
5161
+ temp = norm (temp )
5162
+ temp [0 ] = temp [0 ] * (cmap .N - 1 )
5163
+ temp [1 ] = temp [1 ] * (cmap .N - 1 )
5164
+ temp = temp .astype (int )
5165
+ X = temp [0 ] + cmap .N * temp [1 ]
5166
+ norm = mcolors .NoNorm ()
5167
+
5150
5168
im = mimage .AxesImage (self , cmap , norm , interpolation , origin , extent ,
5151
5169
filternorm = filternorm , filterrad = filterrad ,
5152
5170
resample = resample , ** kwargs )
@@ -5173,7 +5191,6 @@ def imshow(self, X, cmap=None, norm=None, aspect=None,
5173
5191
5174
5192
@staticmethod
5175
5193
def _pcolorargs (funcname , * args , ** kw ):
5176
- # This takes one kwarg, allmatch.
5177
5194
# If allmatch is True, then the incoming X, Y, C must
5178
5195
# have matching dimensions, taking into account that
5179
5196
# X and Y can be 1-D rather than 2-D. This perfect
@@ -5186,9 +5203,25 @@ def _pcolorargs(funcname, *args, **kw):
5186
5203
# is False.
5187
5204
5188
5205
allmatch = kw .pop ("allmatch" , False )
5206
+ norm = kw .pop ("norm" , None )
5207
+ cmap = kw .pop ("cmap" , None )
5189
5208
5190
5209
if len (args ) == 1 :
5191
5210
C = np .asanyarray (args [0 ])
5211
+
5212
+ if (C .ndim == 3 and isinstance (norm , mcolors .BivariateNorm ) or
5213
+ isinstance (cmap , mcolors .BivariateColormap )):
5214
+ if cmap is None :
5215
+ cmap = mcolors .BivariateColormap ()
5216
+ if norm is None :
5217
+ norm = mcolors .BivariateNorm ()
5218
+ C = norm (C )
5219
+ C [0 ] = C [0 ] * (cmap .N - 1 )
5220
+ C [1 ] = C [1 ] * (cmap .N - 1 )
5221
+ C = C .astype (int )
5222
+ C = C [0 ] + cmap .N * C [1 ]
5223
+ C = np .array (C )
5224
+
5192
5225
numRows , numCols = C .shape
5193
5226
if allmatch :
5194
5227
X , Y = np .meshgrid (np .arange (numCols ), np .arange (numRows ))
@@ -5200,6 +5233,18 @@ def _pcolorargs(funcname, *args, **kw):
5200
5233
5201
5234
if len (args ) == 3 :
5202
5235
X , Y , C = [np .asanyarray (a ) for a in args ]
5236
+ if (C .ndim == 3 and isinstance (norm , mcolors .BivariateNorm ) or
5237
+ isinstance (cmap , mcolors .BivariateColormap )):
5238
+ if cmap is None :
5239
+ cmap = mcolors .BivariateColormap ()
5240
+ if norm is None :
5241
+ norm = mcolors .BivariateNorm ()
5242
+ C = norm (C )
5243
+ C [0 ] = C [0 ] * (cmap .N - 1 )
5244
+ C [1 ] = C [1 ] * (cmap .N - 1 )
5245
+ C = C .astype (int )
5246
+ C = C [0 ] + cmap .N * C [1 ]
5247
+ C = np .array (C )
5203
5248
numRows , numCols = C .shape
5204
5249
else :
5205
5250
raise TypeError (
@@ -5382,9 +5427,14 @@ def pcolor(self, *args, **kwargs):
5382
5427
vmin = kwargs .pop ('vmin' , None )
5383
5428
vmax = kwargs .pop ('vmax' , None )
5384
5429
5385
- X , Y , C = self ._pcolorargs ('pcolor' , * args , allmatch = False )
5430
+ kw = {'norm' : norm , 'cmap' : cmap , 'allmatch' : False }
5431
+ X , Y , C = self ._pcolorargs ('pcolor' , * args , ** kw )
5386
5432
Ny , Nx = X .shape
5387
5433
5434
+ if (isinstance (norm , mcolors .BivariateNorm ) or
5435
+ isinstance (cmap , mcolors .BivariateColormap )):
5436
+ norm = mcolors .NoNorm ()
5437
+
5388
5438
# unit conversion allows e.g. datetime objects as axis values
5389
5439
self ._process_unit_info (xdata = X , ydata = Y , kwargs = kwargs )
5390
5440
X = self .convert_xunits (X )
@@ -5450,9 +5500,13 @@ def pcolor(self, *args, **kwargs):
5450
5500
5451
5501
collection .set_alpha (alpha )
5452
5502
collection .set_array (C )
5453
- if norm is not None and not isinstance (norm , mcolors .Normalize ):
5454
- msg = "'norm' must be an instance of 'mcolors.Normalize'"
5503
+
5504
+ isNorm = isinstance (norm , (mcolors .Normalize , mcolors .BivariateNorm ))
5505
+ if norm is not None and not isNorm :
5506
+ msg = "'norm' must be an instance of 'mcolors.Normalize' " \
5507
+ "or 'mcolors.BivariateNorm'"
5455
5508
raise ValueError (msg )
5509
+
5456
5510
collection .set_cmap (cmap )
5457
5511
collection .set_norm (norm )
5458
5512
collection .set_clim (vmin , vmax )
@@ -5582,9 +5636,14 @@ def pcolormesh(self, *args, **kwargs):
5582
5636
5583
5637
allmatch = (shading == 'gouraud' )
5584
5638
5585
- X , Y , C = self ._pcolorargs ('pcolormesh' , * args , allmatch = allmatch )
5639
+ kw = {'norm' : norm , 'cmap' : cmap , 'allmatch' : allmatch }
5640
+ X , Y , C = self ._pcolorargs ('pcolormesh' , * args , ** kw )
5586
5641
Ny , Nx = X .shape
5587
5642
5643
+ if (isinstance (norm , mcolors .BivariateNorm ) or
5644
+ isinstance (cmap , mcolors .BivariateColormap )):
5645
+ norm = mcolors .NoNorm ()
5646
+
5588
5647
# unit conversion allows e.g. datetime objects as axis values
5589
5648
self ._process_unit_info (xdata = X , ydata = Y , kwargs = kwargs )
5590
5649
X = self .convert_xunits (X )
@@ -5723,11 +5782,28 @@ def pcolorfast(self, *args, **kwargs):
5723
5782
cmap = kwargs .pop ('cmap' , None )
5724
5783
vmin = kwargs .pop ('vmin' , None )
5725
5784
vmax = kwargs .pop ('vmax' , None )
5726
- if norm is not None and not isinstance (norm , mcolors .Normalize ):
5727
- msg = "'norm' must be an instance of 'mcolors.Normalize'"
5785
+ isNorm = isinstance (norm , (mcolors .Normalize , mcolors .BivariateNorm ))
5786
+ if norm is not None and not isNorm :
5787
+ msg = "'norm' must be an instance of 'mcolors.Normalize' " \
5788
+ "or 'mcolors.BivariateNorm'"
5728
5789
raise ValueError (msg )
5729
5790
5730
- C = args [- 1 ]
5791
+ C = np .asarray (args [- 1 ])
5792
+
5793
+ if (C .ndim == 3 and isinstance (norm , mcolors .BivariateNorm ) or
5794
+ isinstance (cmap , mcolors .BivariateColormap )):
5795
+ if cmap is None :
5796
+ cmap = mcolors .BivariateColormap ()
5797
+ if norm is None :
5798
+ norm = mcolors .BivariateNorm ()
5799
+ C = norm (C )
5800
+ C [0 ] = C [0 ] * (cmap .N - 1 )
5801
+ C [1 ] = C [1 ] * (cmap .N - 1 )
5802
+ C = C .astype (int )
5803
+ C = C [0 ] + cmap .N * C [1 ]
5804
+ C = np .array (C )
5805
+ norm = mcolors .NoNorm ()
5806
+
5731
5807
nr , nc = C .shape
5732
5808
if len (args ) == 1 :
5733
5809
style = "image"
0 commit comments