@@ -115,7 +115,7 @@ def __call__(self, ax, renderer):
115
115
# time as transSubfigure may otherwise change after this is evaluated.
116
116
return mtransforms .TransformedBbox (
117
117
mtransforms .Bbox .from_bounds (* self ._bounds ),
118
- self ._transform - ax .figure .transSubfigure )
118
+ self ._transform - ax .get_figure ( root = False ) .transSubfigure )
119
119
120
120
121
121
def _process_plot_format (fmt , * , ambiguous_fmt_datakey = False ):
@@ -788,7 +788,7 @@ def get_subplotspec(self):
788
788
def set_subplotspec (self , subplotspec ):
789
789
"""Set the `.SubplotSpec`. associated with the subplot."""
790
790
self ._subplotspec = subplotspec
791
- self ._set_position (subplotspec .get_position (self .figure ))
791
+ self ._set_position (subplotspec .get_position (self .get_figure ( root = False ) ))
792
792
793
793
def get_gridspec (self ):
794
794
"""Return the `.GridSpec` associated with the subplot, or None."""
@@ -959,8 +959,9 @@ def get_xaxis_text1_transform(self, pad_points):
959
959
"""
960
960
labels_align = mpl .rcParams ["xtick.alignment" ]
961
961
return (self .get_xaxis_transform (which = 'tick1' ) +
962
- mtransforms .ScaledTranslation (0 , - 1 * pad_points / 72 ,
963
- self .figure .dpi_scale_trans ),
962
+ mtransforms .ScaledTranslation (
963
+ 0 , - 1 * pad_points / 72 ,
964
+ self .get_figure (root = False ).dpi_scale_trans ),
964
965
"top" , labels_align )
965
966
966
967
def get_xaxis_text2_transform (self , pad_points ):
@@ -985,8 +986,9 @@ def get_xaxis_text2_transform(self, pad_points):
985
986
"""
986
987
labels_align = mpl .rcParams ["xtick.alignment" ]
987
988
return (self .get_xaxis_transform (which = 'tick2' ) +
988
- mtransforms .ScaledTranslation (0 , pad_points / 72 ,
989
- self .figure .dpi_scale_trans ),
989
+ mtransforms .ScaledTranslation (
990
+ 0 , pad_points / 72 ,
991
+ self .get_figure (root = False ).dpi_scale_trans ),
990
992
"bottom" , labels_align )
991
993
992
994
def get_yaxis_transform (self , which = 'grid' ):
@@ -1039,8 +1041,9 @@ def get_yaxis_text1_transform(self, pad_points):
1039
1041
"""
1040
1042
labels_align = mpl .rcParams ["ytick.alignment" ]
1041
1043
return (self .get_yaxis_transform (which = 'tick1' ) +
1042
- mtransforms .ScaledTranslation (- 1 * pad_points / 72 , 0 ,
1043
- self .figure .dpi_scale_trans ),
1044
+ mtransforms .ScaledTranslation (
1045
+ - 1 * pad_points / 72 , 0 ,
1046
+ self .get_figure (root = False ).dpi_scale_trans ),
1044
1047
labels_align , "right" )
1045
1048
1046
1049
def get_yaxis_text2_transform (self , pad_points ):
@@ -1065,8 +1068,9 @@ def get_yaxis_text2_transform(self, pad_points):
1065
1068
"""
1066
1069
labels_align = mpl .rcParams ["ytick.alignment" ]
1067
1070
return (self .get_yaxis_transform (which = 'tick2' ) +
1068
- mtransforms .ScaledTranslation (pad_points / 72 , 0 ,
1069
- self .figure .dpi_scale_trans ),
1071
+ mtransforms .ScaledTranslation (
1072
+ pad_points / 72 , 0 ,
1073
+ self .get_figure (root = False ).dpi_scale_trans ),
1070
1074
labels_align , "left" )
1071
1075
1072
1076
def _update_transScale (self ):
@@ -1173,7 +1177,7 @@ def get_axes_locator(self):
1173
1177
1174
1178
def _set_artist_props (self , a ):
1175
1179
"""Set the boilerplate props for artists added to Axes."""
1176
- a .set_figure (self .figure )
1180
+ a .set_figure (self .get_figure ( root = False ) )
1177
1181
if not a .is_transform_set ():
1178
1182
a .set_transform (self .transData )
1179
1183
@@ -1347,7 +1351,7 @@ def __clear(self):
1347
1351
# the other artists. We use the frame to draw the edges so we are
1348
1352
# setting the edgecolor to None.
1349
1353
self .patch = self ._gen_axes_patch ()
1350
- self .patch .set_figure (self .figure )
1354
+ self .patch .set_figure (self .get_figure ( root = False ) )
1351
1355
self .patch .set_facecolor (self ._facecolor )
1352
1356
self .patch .set_edgecolor ('none' )
1353
1357
self .patch .set_linewidth (0 )
@@ -1522,7 +1526,7 @@ def _set_title_offset_trans(self, title_offset_points):
1522
1526
"""
1523
1527
self .titleOffsetTrans = mtransforms .ScaledTranslation (
1524
1528
0.0 , title_offset_points / 72 ,
1525
- self .figure .dpi_scale_trans )
1529
+ self .get_figure ( root = False ) .dpi_scale_trans )
1526
1530
for _title in (self .title , self ._left_title , self ._right_title ):
1527
1531
_title .set_transform (self .transAxes + self .titleOffsetTrans )
1528
1532
_title .set_clip_box (None )
@@ -1937,7 +1941,7 @@ def apply_aspect(self, position=None):
1937
1941
self ._set_position (position , which = 'active' )
1938
1942
return
1939
1943
1940
- trans = self .get_figure ().transSubfigure
1944
+ trans = self .get_figure (root = False ).transSubfigure
1941
1945
bb = mtransforms .Bbox .unit ().transformed (trans )
1942
1946
# this is the physical aspect of the panel (or figure):
1943
1947
fig_aspect = bb .height / bb .width
@@ -2274,7 +2278,7 @@ def add_child_axes(self, ax):
2274
2278
2275
2279
self .child_axes .append (ax )
2276
2280
ax ._remove_method = functools .partial (
2277
- self .figure ._remove_axes , owners = [self .child_axes ])
2281
+ self .get_figure ( root = False ) ._remove_axes , owners = [self .child_axes ])
2278
2282
self .stale = True
2279
2283
return ax
2280
2284
@@ -3028,7 +3032,8 @@ def _update_title_position(self, renderer):
3028
3032
axs = set ()
3029
3033
axs .update (self .child_axes )
3030
3034
axs .update (self ._twinned_axes .get_siblings (self ))
3031
- axs .update (self .figure ._align_label_groups ['title' ].get_siblings (self ))
3035
+ axs .update (
3036
+ self .get_figure (root = False )._align_label_groups ['title' ].get_siblings (self ))
3032
3037
3033
3038
for ax in self .child_axes : # Child positions must be updated first.
3034
3039
locator = ax .get_axes_locator ()
@@ -3114,7 +3119,7 @@ def draw(self, renderer):
3114
3119
for _axis in self ._axis_map .values ():
3115
3120
artists .remove (_axis )
3116
3121
3117
- if not self .figure .canvas .is_saving ():
3122
+ if not self .get_figure ( root = False ) .canvas .is_saving ():
3118
3123
artists = [
3119
3124
a for a in artists
3120
3125
if not a .get_animated () or isinstance (a , mimage .AxesImage )]
@@ -3142,10 +3147,10 @@ def draw(self, renderer):
3142
3147
artists = [self .patch ] + artists
3143
3148
3144
3149
if artists_rasterized :
3145
- _draw_rasterized (self .figure , artists_rasterized , renderer )
3150
+ _draw_rasterized (self .get_figure ( root = False ) , artists_rasterized , renderer )
3146
3151
3147
3152
mimage ._draw_list_compositing_images (
3148
- renderer , self , artists , self .figure .suppressComposite )
3153
+ renderer , self , artists , self .get_figure ( root = True ) .suppressComposite )
3149
3154
3150
3155
renderer .close_group ('axes' )
3151
3156
self .stale = False
@@ -3154,7 +3159,7 @@ def draw_artist(self, a):
3154
3159
"""
3155
3160
Efficiently redraw a single artist.
3156
3161
"""
3157
- a .draw (self .figure .canvas .get_renderer ())
3162
+ a .draw (self .get_figure ( root = False ) .canvas .get_renderer ())
3158
3163
3159
3164
def redraw_in_frame (self ):
3160
3165
"""
@@ -3164,7 +3169,7 @@ def redraw_in_frame(self):
3164
3169
for artist in [* self ._axis_map .values (),
3165
3170
self .title , self ._left_title , self ._right_title ]:
3166
3171
stack .enter_context (artist ._cm_set (visible = False ))
3167
- self .draw (self .figure .canvas .get_renderer ())
3172
+ self .draw (self .get_figure ( root = False ) .canvas .get_renderer ())
3168
3173
3169
3174
# Axes rectangle characteristics
3170
3175
@@ -4472,7 +4477,7 @@ def get_tightbbox(self, renderer=None, call_axes_locator=True,
4472
4477
4473
4478
bb = []
4474
4479
if renderer is None :
4475
- renderer = self .figure ._get_renderer ()
4480
+ renderer = self .get_figure ( root = False ) ._get_renderer ()
4476
4481
4477
4482
if not self .get_visible ():
4478
4483
return None
@@ -4523,9 +4528,9 @@ def _make_twin_axes(self, *args, **kwargs):
4523
4528
raise ValueError ("Twinned Axes may share only one axis" )
4524
4529
ss = self .get_subplotspec ()
4525
4530
if ss :
4526
- twin = self .figure .add_subplot (ss , * args , ** kwargs )
4531
+ twin = self .get_figure ( root = False ) .add_subplot (ss , * args , ** kwargs )
4527
4532
else :
4528
- twin = self .figure .add_axes (
4533
+ twin = self .get_figure ( root = False ) .add_axes (
4529
4534
self .get_position (True ), * args , ** kwargs ,
4530
4535
axes_locator = _TransformedBoundsLocator (
4531
4536
[0 , 0 , 1 , 1 ], self .transAxes ))
@@ -4754,6 +4759,9 @@ def __init__(self, figure, artists):
4754
4759
self .figure = figure
4755
4760
self .artists = artists
4756
4761
4762
+ def get_figure (self , ** kwargs ):
4763
+ return self .figure
4764
+
4757
4765
@martist .allow_rasterization
4758
4766
def draw (self , renderer ):
4759
4767
for a in self .artists :
0 commit comments