@@ -5081,12 +5081,30 @@ def imshow(self, X, cmap=None, norm=None, aspect=None,
5081
5081
if not self ._hold :
5082
5082
self .cla ()
5083
5083
5084
- if norm is not None and not isinstance (norm , mcolors .Normalize ):
5085
- msg = "'norm' must be an instance of 'mcolors.Normalize'"
5084
+ isNorm = isinstance (norm , (mcolors .Normalize , mcolors .BivariateNorm ))
5085
+ if norm is not None and not isNorm :
5086
+ msg = "'norm' must be an instance of 'mcolors.Normalize' " \
5087
+ "or 'mcolors.BivariateNorm'"
5086
5088
raise ValueError (msg )
5089
+
5087
5090
if aspect is None :
5088
5091
aspect = rcParams ['image.aspect' ]
5089
5092
self .set_aspect (aspect )
5093
+
5094
+ temp = np .asarray (X )
5095
+ if (temp .ndim == 3 and isinstance (norm , mcolors .BivariateNorm ) or
5096
+ isinstance (cmap , mcolors .BivariateColormap )):
5097
+ if cmap is None :
5098
+ cmap = mcolors .BivariateColormap ()
5099
+ if norm is None :
5100
+ norm = mcolors .BivariateNorm ()
5101
+ temp = norm (temp )
5102
+ temp [0 ] = temp [0 ] * (cmap .N - 1 )
5103
+ temp [1 ] = temp [1 ] * (cmap .N - 1 )
5104
+ temp = temp .astype (int )
5105
+ X = temp [0 ] + cmap .N * temp [1 ]
5106
+ norm = mcolors .NoNorm ()
5107
+
5090
5108
im = mimage .AxesImage (self , cmap , norm , interpolation , origin , extent ,
5091
5109
filternorm = filternorm , filterrad = filterrad ,
5092
5110
resample = resample , ** kwargs )
@@ -5113,7 +5131,6 @@ def imshow(self, X, cmap=None, norm=None, aspect=None,
5113
5131
5114
5132
@staticmethod
5115
5133
def _pcolorargs (funcname , * args , ** kw ):
5116
- # This takes one kwarg, allmatch.
5117
5134
# If allmatch is True, then the incoming X, Y, C must
5118
5135
# have matching dimensions, taking into account that
5119
5136
# X and Y can be 1-D rather than 2-D. This perfect
@@ -5126,9 +5143,25 @@ def _pcolorargs(funcname, *args, **kw):
5126
5143
# is False.
5127
5144
5128
5145
allmatch = kw .pop ("allmatch" , False )
5146
+ norm = kw .pop ("norm" , None )
5147
+ cmap = kw .pop ("cmap" , None )
5129
5148
5130
5149
if len (args ) == 1 :
5131
5150
C = np .asanyarray (args [0 ])
5151
+
5152
+ if (C .ndim == 3 and isinstance (norm , mcolors .BivariateNorm ) or
5153
+ isinstance (cmap , mcolors .BivariateColormap )):
5154
+ if cmap is None :
5155
+ cmap = mcolors .BivariateColormap ()
5156
+ if norm is None :
5157
+ norm = mcolors .BivariateNorm ()
5158
+ C = norm (C )
5159
+ C [0 ] = C [0 ] * (cmap .N - 1 )
5160
+ C [1 ] = C [1 ] * (cmap .N - 1 )
5161
+ C = C .astype (int )
5162
+ C = C [0 ] + cmap .N * C [1 ]
5163
+ C = np .array (C )
5164
+
5132
5165
numRows , numCols = C .shape
5133
5166
if allmatch :
5134
5167
X , Y = np .meshgrid (np .arange (numCols ), np .arange (numRows ))
@@ -5140,6 +5173,18 @@ def _pcolorargs(funcname, *args, **kw):
5140
5173
5141
5174
if len (args ) == 3 :
5142
5175
X , Y , C = [np .asanyarray (a ) for a in args ]
5176
+ if (C .ndim == 3 and isinstance (norm , mcolors .BivariateNorm ) or
5177
+ isinstance (cmap , mcolors .BivariateColormap )):
5178
+ if cmap is None :
5179
+ cmap = mcolors .BivariateColormap ()
5180
+ if norm is None :
5181
+ norm = mcolors .BivariateNorm ()
5182
+ C = norm (C )
5183
+ C [0 ] = C [0 ] * (cmap .N - 1 )
5184
+ C [1 ] = C [1 ] * (cmap .N - 1 )
5185
+ C = C .astype (int )
5186
+ C = C [0 ] + cmap .N * C [1 ]
5187
+ C = np .array (C )
5143
5188
numRows , numCols = C .shape
5144
5189
else :
5145
5190
raise TypeError (
@@ -5325,9 +5370,14 @@ def pcolor(self, *args, **kwargs):
5325
5370
vmin = kwargs .pop ('vmin' , None )
5326
5371
vmax = kwargs .pop ('vmax' , None )
5327
5372
5328
- X , Y , C = self ._pcolorargs ('pcolor' , * args , allmatch = False )
5373
+ kw = {'norm' : norm , 'cmap' : cmap , 'allmatch' : False }
5374
+ X , Y , C = self ._pcolorargs ('pcolor' , * args , ** kw )
5329
5375
Ny , Nx = X .shape
5330
5376
5377
+ if (isinstance (norm , mcolors .BivariateNorm ) or
5378
+ isinstance (cmap , mcolors .BivariateColormap )):
5379
+ norm = mcolors .NoNorm ()
5380
+
5331
5381
# unit conversion allows e.g. datetime objects as axis values
5332
5382
self ._process_unit_info (xdata = X , ydata = Y , kwargs = kwargs )
5333
5383
X = self .convert_xunits (X )
@@ -5393,9 +5443,13 @@ def pcolor(self, *args, **kwargs):
5393
5443
5394
5444
collection .set_alpha (alpha )
5395
5445
collection .set_array (C )
5396
- if norm is not None and not isinstance (norm , mcolors .Normalize ):
5397
- msg = "'norm' must be an instance of 'mcolors.Normalize'"
5446
+
5447
+ isNorm = isinstance (norm , (mcolors .Normalize , mcolors .BivariateNorm ))
5448
+ if norm is not None and not isNorm :
5449
+ msg = "'norm' must be an instance of 'mcolors.Normalize' " \
5450
+ "or 'mcolors.BivariateNorm'"
5398
5451
raise ValueError (msg )
5452
+
5399
5453
collection .set_cmap (cmap )
5400
5454
collection .set_norm (norm )
5401
5455
collection .set_clim (vmin , vmax )
@@ -5525,9 +5579,14 @@ def pcolormesh(self, *args, **kwargs):
5525
5579
5526
5580
allmatch = (shading == 'gouraud' )
5527
5581
5528
- X , Y , C = self ._pcolorargs ('pcolormesh' , * args , allmatch = allmatch )
5582
+ kw = {'norm' : norm , 'cmap' : cmap , 'allmatch' : allmatch }
5583
+ X , Y , C = self ._pcolorargs ('pcolormesh' , * args , ** kw )
5529
5584
Ny , Nx = X .shape
5530
5585
5586
+ if (isinstance (norm , mcolors .BivariateNorm ) or
5587
+ isinstance (cmap , mcolors .BivariateColormap )):
5588
+ norm = mcolors .NoNorm ()
5589
+
5531
5590
# unit conversion allows e.g. datetime objects as axis values
5532
5591
self ._process_unit_info (xdata = X , ydata = Y , kwargs = kwargs )
5533
5592
X = self .convert_xunits (X )
@@ -5666,11 +5725,28 @@ def pcolorfast(self, *args, **kwargs):
5666
5725
cmap = kwargs .pop ('cmap' , None )
5667
5726
vmin = kwargs .pop ('vmin' , None )
5668
5727
vmax = kwargs .pop ('vmax' , None )
5669
- if norm is not None and not isinstance (norm , mcolors .Normalize ):
5670
- msg = "'norm' must be an instance of 'mcolors.Normalize'"
5728
+ isNorm = isinstance (norm , (mcolors .Normalize , mcolors .BivariateNorm ))
5729
+ if norm is not None and not isNorm :
5730
+ msg = "'norm' must be an instance of 'mcolors.Normalize' " \
5731
+ "or 'mcolors.BivariateNorm'"
5671
5732
raise ValueError (msg )
5672
5733
5673
- C = args [- 1 ]
5734
+ C = np .asarray (args [- 1 ])
5735
+
5736
+ if (C .ndim == 3 and isinstance (norm , mcolors .BivariateNorm ) or
5737
+ isinstance (cmap , mcolors .BivariateColormap )):
5738
+ if cmap is None :
5739
+ cmap = mcolors .BivariateColormap ()
5740
+ if norm is None :
5741
+ norm = mcolors .BivariateNorm ()
5742
+ C = norm (C )
5743
+ C [0 ] = C [0 ] * (cmap .N - 1 )
5744
+ C [1 ] = C [1 ] * (cmap .N - 1 )
5745
+ C = C .astype (int )
5746
+ C = C [0 ] + cmap .N * C [1 ]
5747
+ C = np .array (C )
5748
+ norm = mcolors .NoNorm ()
5749
+
5674
5750
nr , nc = C .shape
5675
5751
if len (args ) == 1 :
5676
5752
style = "image"
0 commit comments