@@ -1053,10 +1053,6 @@ def cla(self):
10531053 size = rcParams ['axes.titlesize' ],
10541054 weight = rcParams ['axes.titleweight' ])
10551055
1056- title_offset_points = rcParams ['axes.titlepad' ]
1057- self .titleOffsetTrans = mtransforms .ScaledTranslation (
1058- 0.0 , title_offset_points / 72.0 ,
1059- self .figure .dpi_scale_trans )
10601056 self .title = mtext .Text (
10611057 x = 0.5 , y = 1.0 , text = '' ,
10621058 fontproperties = props ,
@@ -1074,10 +1070,12 @@ def cla(self):
10741070 verticalalignment = 'baseline' ,
10751071 horizontalalignment = 'right' ,
10761072 )
1073+ title_offset_points = rcParams ['axes.titlepad' ]
1074+ # refactor this out so it can be called in ax.set_title if
1075+ # pad argument used...
1076+ self ._set_title_offset_trans (title_offset_points )
10771077
10781078 for _title in (self .title , self ._left_title , self ._right_title ):
1079- _title .set_transform (self .transAxes + self .titleOffsetTrans )
1080- _title .set_clip_box (None )
10811079 self ._set_artist_props (_title )
10821080
10831081 # The patch draws the background of the axes. We want this to be below
@@ -1134,6 +1132,18 @@ def set_facecolor(self, color):
11341132 return self .patch .set_facecolor (color )
11351133 set_fc = set_facecolor
11361134
1135+ def _set_title_offset_trans (self , title_offset_points ):
1136+ """
1137+ Set the offset for the title either from rcParams['axes.titlepad']
1138+ or from set_title kwarg ``pad``.
1139+ """
1140+ self .titleOffsetTrans = mtransforms .ScaledTranslation (
1141+ 0.0 , title_offset_points / 72.0 ,
1142+ self .figure .dpi_scale_trans )
1143+ for _title in (self .title , self ._left_title , self ._right_title ):
1144+ _title .set_transform (self .transAxes + self .titleOffsetTrans )
1145+ _title .set_clip_box (None )
1146+
11371147 def set_prop_cycle (self , * args , ** kwargs ):
11381148 """
11391149 Set the property cycle for any future plot commands on this Axes.
0 commit comments