15
15
16
16
'''
17
17
18
- import matplotlib . numerix as nx
19
- from matplotlib . mlab import meshgrid , linspace
20
- from matplotlib .numerix . mlab import amin , amax
21
- from matplotlib import colors , cm , ticker
22
- from matplotlib .cbook import iterable , is_string_like
23
- from matplotlib .transforms import Interval , Value , PBox
24
- from matplotlib .lines import Line2D
25
- from matplotlib .patches import Polygon
26
- from matplotlib import rcParams
27
- from matplotlib .collections import LineCollection
28
- from matplotlib .contour import ContourSet
29
- from matplotlib .axes import Axes
18
+ import numpy as npy
19
+ import matplotlib as mpl
20
+ import matplotlib .colors as colors
21
+ import matplotlib . cm as cm
22
+ import matplotlib .ticker as ticker
23
+ import matplotlib .cbook as cbook
24
+ import matplotlib .transforms as transforms
25
+ import matplotlib .lines as lines
26
+ import matplotlib . patches as patches
27
+ import matplotlib .collections as collections
28
+ import matplotlib .contour as contour
29
+ import matplotlib .axes as axes
30
30
31
31
make_axes_kw_doc = '''
32
32
fraction = 0.15; fraction of original axes to use for colorbar
@@ -144,7 +144,7 @@ def __init__(self, ax, cmap=None,
144
144
self .filled = filled
145
145
self .solids = None
146
146
self .lines = None
147
- if iterable (ticks ):
147
+ if cbook . iterable (ticks ):
148
148
self .locator = ticker .FixedLocator (ticks , nbins = len (ticks ))
149
149
else :
150
150
self .locator = ticks # Handle default in _ticker()
@@ -153,7 +153,7 @@ def __init__(self, ax, cmap=None,
153
153
self .formatter = ticker .LogFormatter ()
154
154
else :
155
155
self .formatter = ticker .ScalarFormatter ()
156
- elif is_string_like (format ):
156
+ elif cbook . is_string_like (format ):
157
157
self .formatter = ticker .FormatStrFormatter (format )
158
158
else :
159
159
self .formatter = format # Assume it is a Formatter
@@ -168,7 +168,7 @@ def draw_all(self):
168
168
self ._process_values ()
169
169
self ._find_range ()
170
170
X , Y = self ._mesh ()
171
- C = self ._values [:,nx . NewAxis ]
171
+ C = self ._values [:,npy . newaxis ]
172
172
self ._config_axes (X , Y )
173
173
if self .filled :
174
174
self ._add_solids (X , Y , C )
@@ -181,14 +181,14 @@ def _config_axes(self, X, Y):
181
181
ax .set_frame_on (False )
182
182
ax .set_navigate (False )
183
183
x , y = self ._outline (X , Y )
184
- ax .set_xlim (amin (x ), amax (x ))
185
- ax .set_ylim (amin (y ), amax (y ))
184
+ ax .set_xlim (npy . amin (x ), npy . amax (x ))
185
+ ax .set_ylim (npy . amin (y ), npy . amax (y ))
186
186
ax .update_datalim_numerix (x , y )
187
- self .outline = Line2D (x , y , color = rcParams ['axes.edgecolor' ],
188
- linewidth = rcParams ['axes.linewidth' ])
187
+ self .outline = lines . Line2D (x , y , color = mpl . rcParams ['axes.edgecolor' ],
188
+ linewidth = mpl . rcParams ['axes.linewidth' ])
189
189
ax .add_artist (self .outline )
190
- c = rcParams ['axes.facecolor' ]
191
- self .patch = Polygon (zip (x ,y ), edgecolor = c ,
190
+ c = mpl . rcParams ['axes.facecolor' ]
191
+ self .patch = patches . Polygon (zip (x ,y ), edgecolor = c ,
192
192
facecolor = c ,
193
193
linewidth = 0.01 ,
194
194
zorder = - 1 )
@@ -220,10 +220,10 @@ def _outline(self, X, Y):
220
220
Return x, y arrays of colorbar bounding polygon,
221
221
taking orientation into account.
222
222
'''
223
- N = nx .shape ( X ) [0 ]
223
+ N = X .shape [0 ]
224
224
ii = [0 , 1 , N - 2 , N - 1 , 2 * N - 1 , 2 * N - 2 , N + 1 , N , 0 ]
225
- x = nx .take (nx .ravel (nx .transpose (X )), ii )
226
- y = nx .take (nx .ravel (nx .transpose (Y )), ii )
225
+ x = npy .take (npy .ravel (npy .transpose (X )), ii )
226
+ y = npy .take (npy .ravel (npy .transpose (Y )), ii )
227
227
if self .orientation == 'horizontal' :
228
228
return y ,x
229
229
return x ,y
@@ -232,7 +232,7 @@ def _edges(self, X, Y):
232
232
'''
233
233
Return the separator line segments; helper for _add_solids.
234
234
'''
235
- N = nx .shape ( X ) [0 ]
235
+ N = X .shape [0 ]
236
236
# Using the non-array form of these line segments is much
237
237
# simpler than making them into arrays.
238
238
if self .orientation == 'vertical' :
@@ -249,17 +249,17 @@ def _add_solids(self, X, Y, C):
249
249
if self .orientation == 'vertical' :
250
250
args = (X , Y , C )
251
251
else :
252
- args = (nx .transpose (Y ), nx .transpose (X ), nx .transpose (C ))
252
+ args = (npy .transpose (Y ), npy .transpose (X ), npy .transpose (C ))
253
253
kw = {'cmap' :self .cmap , 'norm' :self .norm ,
254
254
'shading' :'flat' , 'alpha' :self .alpha }
255
255
col = self .ax .pcolor (* args , ** kw )
256
256
#self.add_observer(col) # We should observe, not be observed...
257
257
self .solids = col
258
258
if self .drawedges :
259
- self .dividers = LineCollection (self ._edges (X ,Y ),
260
- colors = (rcParams ['axes.edgecolor' ],),
261
- linewidths = (0.5 * rcParams ['axes.linewidth' ],)
262
- )
259
+ self .dividers = collections . LineCollection (self ._edges (X ,Y ),
260
+ colors = (mpl . rcParams ['axes.edgecolor' ],),
261
+ linewidths = (0.5 * mpl . rcParams ['axes.linewidth' ],)
262
+ )
263
263
self .ax .add_collection (self .dividers )
264
264
265
265
def add_lines (self , levels , colors , linewidths ):
@@ -270,13 +270,13 @@ def add_lines(self, levels, colors, linewidths):
270
270
dummy , y = self ._locate (levels )
271
271
if len (y ) <> N :
272
272
raise ValueError ("levels are outside colorbar range" )
273
- x = nx .array ([0.0 , 1.0 ])
274
- X , Y = meshgrid (x ,y )
273
+ x = npy .array ([0.0 , 1.0 ])
274
+ X , Y = npy . meshgrid (x ,y )
275
275
if self .orientation == 'vertical' :
276
276
xy = [zip (X [i ], Y [i ]) for i in range (N )]
277
277
else :
278
278
xy = [zip (Y [i ], X [i ]) for i in range (N )]
279
- col = LineCollection (xy , linewidths = linewidths )
279
+ col = collections . LineCollection (xy , linewidths = linewidths )
280
280
self .lines = col
281
281
col .set_color (colors )
282
282
self .ax .add_collection (col )
@@ -303,14 +303,16 @@ def _ticker(self):
303
303
b = self ._boundaries [self ._inside ]
304
304
locator = ticker .FixedLocator (b , nbins = 10 )
305
305
if isinstance (self .norm , colors .NoNorm ):
306
- intv = Interval (Value (self ._values [0 ]), Value (self ._values [- 1 ]))
306
+ intv = transforms .Interval (transforms .Value (self ._values [0 ]),
307
+ transforms .Value (self ._values [- 1 ]))
307
308
else :
308
- intv = Interval (Value (self .vmin ), Value (self .vmax ))
309
+ intv = transforms .Interval (transforms .Value (self .vmin ),
310
+ transforms .Value (self .vmax ))
309
311
locator .set_view_interval (intv )
310
312
locator .set_data_interval (intv )
311
313
formatter .set_view_interval (intv )
312
314
formatter .set_data_interval (intv )
313
- b = nx .array (locator ())
315
+ b = npy .array (locator ())
314
316
b , ticks = self ._locate (b )
315
317
formatter .set_locs (b )
316
318
ticklabels = [formatter (t ) for t in b ]
@@ -326,28 +328,28 @@ def _process_values(self, b=None):
326
328
if b is None :
327
329
b = self .boundaries
328
330
if b is not None :
329
- self ._boundaries = nx .array (b )
331
+ self ._boundaries = npy .array (b )
330
332
if self .values is None :
331
333
self ._values = 0.5 * (self ._boundaries [:- 1 ]
332
334
+ self ._boundaries [1 :])
333
335
if isinstance (self .norm , colors .NoNorm ):
334
- self ._values = (self ._values + 0.00001 ).astype (nx . Int16 )
336
+ self ._values = (self ._values + 0.00001 ).astype (npy . int16 )
335
337
return
336
- self ._values = nx .array (self .values )
338
+ self ._values = npy .array (self .values )
337
339
return
338
340
if self .values is not None :
339
- self ._values = nx .array (self .values )
341
+ self ._values = npy .array (self .values )
340
342
if self .boundaries is None :
341
- b = nx .zeros (len (self .values )+ 1 , 'd' )
343
+ b = npy .zeros (len (self .values )+ 1 , 'd' )
342
344
b [1 :- 1 ] = 0.5 * (self ._values [:- 1 ] - self ._values [1 :])
343
345
b [0 ] = 2.0 * b [1 ] - b [2 ]
344
346
b [- 1 ] = 2.0 * b [- 2 ] - b [- 3 ]
345
347
self ._boundaries = b
346
348
return
347
- self ._boundaries = nx .array (self .boundaries )
349
+ self ._boundaries = npy .array (self .boundaries )
348
350
return
349
351
if isinstance (self .norm , colors .NoNorm ):
350
- b = nx .arange (self .norm .vmin , self .norm .vmax + 2 ) - 0.5
352
+ b = npy .arange (self .norm .vmin , self .norm .vmax + 2 ) - 0.5
351
353
else :
352
354
b = self .norm .inverse (self ._uniform_y (self .cmap .N + 1 ))
353
355
self ._process_values (b )
@@ -388,19 +390,19 @@ def _uniform_y(self, N):
388
390
spaced boundaries, plus ends if required.
389
391
'''
390
392
if self .extend == 'neither' :
391
- y = linspace (0 , 1 , N )
393
+ y = npy . linspace (0 , 1 , N )
392
394
else :
393
395
if self .extend == 'both' :
394
- y = nx .zeros (N + 2 , 'd' )
396
+ y = npy .zeros (N + 2 , 'd' )
395
397
y [0 ] = - 0.05
396
398
y [- 1 ] = 1.05
397
399
elif self .extend == 'min' :
398
- y = nx .zeros (N + 1 , 'd' )
400
+ y = npy .zeros (N + 1 , 'd' )
399
401
y [0 ] = - 0.05
400
402
else :
401
- y = nx .zeros (N + 1 , 'd' )
403
+ y = npy .zeros (N + 1 , 'd' )
402
404
y [- 1 ] = 1.05
403
- y [self ._inside ] = linspace (0 , 1 , N )
405
+ y [self ._inside ] = npy . linspace (0 , 1 , N )
404
406
return y
405
407
406
408
def _proportional_y (self ):
@@ -425,13 +427,13 @@ def _mesh(self):
425
427
transposition for a horizontal colorbar are done outside
426
428
this function.
427
429
'''
428
- x = nx .array ([0.0 , 1.0 ])
430
+ x = npy .array ([0.0 , 1.0 ])
429
431
if self .spacing == 'uniform' :
430
432
y = self ._uniform_y (self ._central_N ())
431
433
else :
432
434
y = self ._proportional_y ()
433
435
self ._y = y
434
- X , Y = meshgrid (x ,y )
436
+ X , Y = npy . meshgrid (x ,y )
435
437
if self .extend in ('min' , 'both' ):
436
438
X [0 ,:] = 0.5
437
439
if self .extend in ('max' , 'both' ):
@@ -457,19 +459,19 @@ def _locate(self, x):
457
459
# floating point errors.
458
460
xn = self .norm (x , clip = False ).filled ()
459
461
in_cond = (xn > - 0.001 ) & (xn < 1.001 )
460
- xn = nx .compress (in_cond , xn )
461
- xout = nx .compress (in_cond , x )
462
+ xn = npy .compress (in_cond , xn )
463
+ xout = npy .compress (in_cond , x )
462
464
# The rest is linear interpolation with clipping.
463
465
y = self ._y
464
466
N = len (b )
465
- ii = nx .minimum (nx .searchsorted (b , xn ), N - 1 )
466
- i0 = nx .maximum (ii - 1 , 0 )
467
+ ii = npy .minimum (npy .searchsorted (b , xn ), N - 1 )
468
+ i0 = npy .maximum (ii - 1 , 0 )
467
469
#db = b[ii] - b[i0] (does not work with Numeric)
468
- db = nx .take (b , ii ) - nx .take (b , i0 )
469
- db = nx .where (i0 == ii , 1.0 , db )
470
+ db = npy .take (b , ii ) - npy .take (b , i0 )
471
+ db = npy .where (i0 == ii , 1.0 , db )
470
472
#dy = y[ii] - y[i0]
471
- dy = nx .take (y , ii ) - nx .take (y , i0 )
472
- z = nx .take (y , i0 ) + (xn - nx .take (b ,i0 ))* dy / db
473
+ dy = npy .take (y , ii ) - npy .take (y , i0 )
474
+ z = npy .take (y , i0 ) + (xn - npy .take (b ,i0 ))* dy / db
473
475
return xout , z
474
476
475
477
def set_alpha (self , alpha ):
@@ -486,7 +488,7 @@ def __init__(self, ax, mappable, **kw):
486
488
kw ['cmap' ] = mappable .cmap
487
489
kw ['norm' ] = mappable .norm
488
490
kw ['alpha' ] = mappable .get_alpha ()
489
- if isinstance (mappable , ContourSet ):
491
+ if isinstance (mappable , contour . ContourSet ):
490
492
CS = mappable
491
493
kw ['boundaries' ] = CS ._levels
492
494
kw ['values' ] = CS .cvalues
@@ -505,7 +507,7 @@ def add_lines(self, CS):
505
507
'''
506
508
Add the lines from a non-filled ContourSet to the colorbar.
507
509
'''
508
- if not isinstance (CS , ContourSet ) or CS .filled :
510
+ if not isinstance (CS , contour . ContourSet ) or CS .filled :
509
511
raise ValueError ('add_lines is only for a ContourSet of lines' )
510
512
tcolors = [c [0 ] for c in CS .tcolors ]
511
513
tlinewidths = [t [0 ] for t in CS .tlinewidths ]
@@ -530,7 +532,7 @@ def notify(self, mappable):
530
532
#if self.vmin != self.norm.vmin or self.vmax != self.norm.vmax:
531
533
# self.ax.cla()
532
534
# self.draw_all()
533
- if isinstance (self .mappable , ContourSet ):
535
+ if isinstance (self .mappable , contour . ContourSet ):
534
536
CS = self .mappable
535
537
if not CS .filled :
536
538
self .add_lines (CS )
@@ -547,8 +549,8 @@ def make_axes(parent, **kw):
547
549
fraction = kw .pop ('fraction' , 0.15 )
548
550
shrink = kw .pop ('shrink' , 1.0 )
549
551
aspect = kw .pop ('aspect' , 20 )
550
- #pb = PBox(parent.get_position())
551
- pb = PBox (parent .get_position (original = True ))
552
+ #pb = transforms. PBox(parent.get_position())
553
+ pb = transforms . PBox (parent .get_position (original = True ))
552
554
if orientation == 'vertical' :
553
555
pad = kw .pop ('pad' , 0.05 )
554
556
x1 = 1.0 - fraction
@@ -591,14 +593,14 @@ def make_axes(parent, **kw):
591
593
generate the axes, not when the axes object is generated first and
592
594
then fig.add_axes(ax) is called. I don't understand this. - EF
593
595
594
- class ColorbarAxes(Axes):
596
+ class ColorbarAxes(axes. Axes):
595
597
def __init__(self, parent, **kw):
596
598
orientation = kw.setdefault('orientation', 'vertical')
597
599
fraction = kw.pop('fraction', 0.15)
598
600
shrink = kw.pop('shrink', 1.0)
599
601
aspect = kw.pop('aspect', 20)
600
602
self.cbkw = kw
601
- pb = PBox(parent.get_position())
603
+ pb = transforms. PBox(parent.get_position())
602
604
if orientation == 'vertical':
603
605
pb1, pbcb = pb.splitx(1.0-fraction)
604
606
pbcb.shrink(1.0, shrink).anchor('C')
@@ -613,7 +615,7 @@ def __init__(self, parent, **kw):
613
615
parent.set_position(pb1)
614
616
parent.set_anchor(panchor)
615
617
fig = parent.get_figure()
616
- Axes.__init__(self, fig, pbcb)
618
+ axes. Axes.__init__(self, fig, pbcb)
617
619
fig.add_axes(self)
618
620
self.set_aspect(aspect, anchor=anchor, adjustable='box')
619
621
0 commit comments