21
21
from matplotlib import lines as mlines
22
22
from matplotlib import mlab
23
23
from matplotlib import patches as mpatches
24
- from matplotlib import path as mpath
25
24
from matplotlib import quiver as mquiver
26
25
from matplotlib import scale as mscale
27
26
from matplotlib import table as mtable
@@ -771,14 +770,13 @@ def cla(self):
771
770
772
771
self .grid (self ._gridOn )
773
772
props = font_manager .FontProperties (size = rcParams ['axes.titlesize' ])
774
- self .titleOffsetTrans = mtransforms .Affine2D ()
775
- self .title = mtext .Text (
776
- x = 0.5 , y = 1.00 , text = '' ,
773
+ self .title = mtext .Text (
774
+ x = 0.5 , y = 1.02 , text = '' ,
777
775
fontproperties = props ,
778
776
verticalalignment = 'bottom' ,
779
777
horizontalalignment = 'center' ,
780
778
)
781
- self .title .set_transform (self .transAxes + self . titleOffsetTrans )
779
+ self .title .set_transform (self .transAxes )
782
780
self .title .set_clip_box (None )
783
781
784
782
self ._set_artist_props (self .title )
@@ -802,8 +800,6 @@ def cla(self):
802
800
self .xaxis .set_clip_path (self .axesPatch )
803
801
self .yaxis .set_clip_path (self .axesPatch )
804
802
805
- self .titleOffsetTrans .clear ()
806
-
807
803
def clear (self ):
808
804
'clear the axes'
809
805
self .cla ()
@@ -909,14 +905,14 @@ def get_data_ratio(self):
909
905
ysize = max (math .fabs (ymax - ymin ), 1e-30 )
910
906
return ysize / xsize
911
907
912
- def apply_aspect (self , currentPosition ):
908
+ def apply_aspect (self ):
913
909
'''
914
910
Use self._aspect and self._adjustable to modify the
915
911
axes box or the view limits.
916
912
'''
917
913
aspect = self .get_aspect ()
918
914
if aspect == 'auto' :
919
- self .set_position (currentPosition , 'active' )
915
+ self .set_position ( self . _originalPosition , 'active' )
920
916
return
921
917
922
918
if aspect == 'equal' :
@@ -933,7 +929,7 @@ def apply_aspect(self, currentPosition):
933
929
fig_aspect = figH / figW
934
930
if self ._adjustable == 'box' :
935
931
box_aspect = A * self .get_data_ratio ()
936
- pb = currentPosition .frozen ()
932
+ pb = self . _originalPosition .frozen ()
937
933
pb1 = pb .shrunk_to_aspect (box_aspect , pb , fig_aspect )
938
934
self .set_position (pb1 .anchored (self .get_anchor (), pb ), 'active' )
939
935
return
@@ -1141,7 +1137,7 @@ def add_collection(self, collection, autolim=True):
1141
1137
self ._set_artist_props (collection )
1142
1138
collection .set_clip_path (self .axesPatch )
1143
1139
if autolim :
1144
- if len (collection ._paths ):
1140
+ if collection . _paths and len (collection ._paths ):
1145
1141
self .update_datalim (collection .get_datalim (self .transData ))
1146
1142
collection ._remove_method = lambda h : self .collections .remove (h )
1147
1143
@@ -1293,48 +1289,25 @@ def autoscale_view(self, tight=False, scalex=True, scaley=True):
1293
1289
YL = ylocator .autoscale ()
1294
1290
self .set_ybound (YL )
1295
1291
1296
- def adjust_for_axis_text (self , renderer ):
1297
- pad_pixels = rcParams ['xtick.major.pad' ] * self .figure .dpi / 72.0
1298
- inverse_transFigure = self .figure .transFigure .inverted ()
1299
- t_text , b_text = self .xaxis .get_text_heights (renderer )
1300
- l_text , r_text = self .yaxis .get_text_widths (renderer )
1301
- title_height = self .title .get_window_extent (renderer ).height
1302
- title_height += pad_pixels * 2.0
1303
- original_t_text = t_text
1304
-
1305
- ((l_text , t_text ),
1306
- (r_text , b_text ),
1307
- (dummy , title_height )) = inverse_transFigure .transform (
1308
- ((l_text , t_text ),
1309
- (r_text , b_text ),
1310
- (0.0 , title_height )))
1311
- x0 , y0 , x1 , y1 = self .get_position (True ).extents
1312
- # Adjust the title
1313
- self .titleOffsetTrans .clear ().translate (
1314
- 0 , original_t_text + pad_pixels * 2.0 )
1315
- return mtransforms .Bbox .from_extents (
1316
- x0 + l_text , y0 + b_text , x1 - r_text ,
1317
- y1 - t_text - title_height )
1318
-
1319
1292
#### Drawing
1320
1293
def draw (self , renderer = None , inframe = False ):
1321
1294
"Draw everything (plot lines, axes, labels)"
1322
- if renderer is None :
1295
+ if renderer is None :
1323
1296
renderer = self ._cachedRenderer
1324
1297
1325
1298
if renderer is None :
1326
1299
raise RuntimeError ('No renderer defined' )
1327
1300
if not self .get_visible (): return
1328
1301
renderer .open_group ('axes' )
1329
-
1330
- currentPosition = self .adjust_for_axis_text (renderer )
1331
- self .apply_aspect (currentPosition )
1302
+ self .apply_aspect ()
1332
1303
1333
1304
if self .axison and self ._frameon :
1334
1305
self .axesPatch .draw (renderer )
1335
1306
1336
1307
artists = []
1337
1308
1309
+
1310
+
1338
1311
if len (self .images )<= 1 or renderer .option_image_nocomposite ():
1339
1312
for im in self .images :
1340
1313
im .draw (renderer )
@@ -1346,6 +1319,7 @@ def draw(self, renderer=None, inframe=False):
1346
1319
ims = [(im .make_image (mag ),0 ,0 )
1347
1320
for im in self .images if im .get_visible ()]
1348
1321
1322
+
1349
1323
im = mimage .from_images (self .bbox .height * mag ,
1350
1324
self .bbox .width * mag ,
1351
1325
ims )
@@ -1386,14 +1360,6 @@ def draw(self, renderer=None, inframe=False):
1386
1360
a .draw (renderer )
1387
1361
1388
1362
renderer .close_group ('axes' )
1389
-
1390
- # ### DEBUGGING
1391
- # gc = renderer.new_gc()
1392
- # gc.set_linewidth(2.0)
1393
- # x0, y0, x1, y1 = self.get_position(True).extents
1394
- # renderer.draw_path(gc, mpath.Path(
1395
- # [[x0, y0], [x0, y1], [x1, y1], [x1, y0], [x0, y0]]),
1396
- # self.figure.transFigure)
1397
1363
self ._cachedRenderer = renderer
1398
1364
1399
1365
def draw_artist (self , a ):
0 commit comments