@@ -932,10 +932,23 @@ def cla(self):
932
932
verticalalignment = 'baseline' ,
933
933
horizontalalignment = 'center' ,
934
934
)
935
- self .title .set_transform (self .transAxes + self .titleOffsetTrans )
936
- self .title .set_clip_box (None )
935
+ self ._left_title = mtext .Text (
936
+ x = 0.0 , y = 1.0 , text = '' ,
937
+ fontproperties = props ,
938
+ verticalalignment = 'baseline' ,
939
+ horizontalalignment = 'left' ,
940
+ )
941
+ self ._right_title = mtext .Text (
942
+ x = 1.0 , y = 1.0 , text = '' ,
943
+ fontproperties = props ,
944
+ verticalalignment = 'baseline' ,
945
+ horizontalalignment = 'right' ,
946
+ )
937
947
938
- self ._set_artist_props (self .title )
948
+ for _title in (self .title , self ._left_title , self ._right_title ):
949
+ _title .set_transform (self .transAxes + self .titleOffsetTrans )
950
+ _title .set_clip_box (None )
951
+ self ._set_artist_props (_title )
939
952
940
953
# the patch draws the background of the axes. we want this to
941
954
# be below the other artists; the axesPatch name is
@@ -1990,6 +2003,8 @@ def draw(self, renderer=None, inframe=False):
1990
2003
artists .extend ([self .xaxis , self .yaxis ])
1991
2004
if not inframe :
1992
2005
artists .append (self .title )
2006
+ artists .append (self ._left_title )
2007
+ artists .append (self ._right_title )
1993
2008
artists .extend (self .tables )
1994
2009
if self .legend_ is not None :
1995
2010
artists .append (self .legend_ )
@@ -3100,6 +3115,8 @@ def get_children(self):
3100
3115
children .append (self .legend_ )
3101
3116
children .extend (self .collections )
3102
3117
children .append (self .title )
3118
+ children .append (self ._left_title )
3119
+ children .append (self ._right_title )
3103
3120
children .append (self .patch )
3104
3121
children .extend (self .spines .itervalues ())
3105
3122
return children
@@ -3137,43 +3154,82 @@ def pick(self, *args):
3137
3154
3138
3155
### Labelling
3139
3156
3140
- def get_title (self ):
3141
- """
3142
- Get the title text string.
3143
- """
3144
- return self .title .get_text ()
3145
-
3146
- @docstring .dedent_interpd
3147
- def set_title (self , label , fontdict = None , ** kwargs ):
3148
- """
3149
- Call signature::
3157
+ def get_title (self , loc = "center" ):
3158
+ """Get an axes title.
3150
3159
3151
- set_title(label, fontdict=None, **kwargs):
3160
+ Get one of the three available axes titles. The available titles
3161
+ are positioned above the axes in the center, flush with the left
3162
+ edge, and flush with the right edge.
3152
3163
3153
- Set the title for the axes.
3164
+ Parameters
3165
+ ----------
3166
+ loc : {'center', 'left', 'right'}, str, optional
3167
+ Which title to get, defaults to 'center'
3154
3168
3155
- kwargs are Text properties:
3156
- %(Text)s
3169
+ Returns
3170
+ -------
3171
+ text : :class:`~matplotlib.text.Text`
3172
+ The matplotlib text instance representing the title
3157
3173
3158
- ACCEPTS: str
3174
+ """
3175
+ try :
3176
+ title = {'left' : self ._left_title ,
3177
+ 'center' : self .title ,
3178
+ 'right' : self ._right_title }[loc .lower ()]
3179
+ except KeyError :
3180
+ raise ValueError ("'%s' is not a valid location" % loc )
3181
+ return title
3159
3182
3160
- .. seealso::
3183
+ @docstring .dedent_interpd
3184
+ def set_title (self , label , loc = "center" , fontdict = None , ** kwargs ):
3185
+ """Set a title for the axes.
3186
+
3187
+ Set one of the three available axes titles. The available titles
3188
+ are positioned above the axes in the center, flush with the left
3189
+ edge, and flush with the right edge.
3190
+
3191
+ Parameters
3192
+ ----------
3193
+ label : str
3194
+ Text to use for the title
3195
+ loc : {'center', 'left', 'right'}, str, optional
3196
+ Which title to set, defaults to 'center'
3197
+ fontdict : dict
3198
+ A dictionary controlling the appearance of the title text,
3199
+ the default `fontdict` is:
3200
+ {'fontsize': rcParams['axes.titlesize'],
3201
+ 'verticalalignment': 'baseline',
3202
+ 'horizontalalignment': loc}
3203
+
3204
+ Returns
3205
+ -------
3206
+ text : :class:`~matplotlib.text.Text`
3207
+ The matplotlib text instance representing the title
3208
+
3209
+ Other parameters
3210
+ ----------------
3211
+ Other keyword arguments are text properties, see
3212
+ :class:`~matplotlib.text.Text` for a list of valid text
3213
+ properties.
3161
3214
3162
- :meth:`text`
3163
- for information on how override and the optional args work
3164
3215
"""
3216
+ try :
3217
+ title = {'left' : self ._left_title ,
3218
+ 'center' : self .title ,
3219
+ 'right' : self ._right_title }[loc .lower ()]
3220
+ except KeyError :
3221
+ raise ValueError ("'%s' is not a valid location" % loc )
3165
3222
default = {
3166
3223
'fontsize' : rcParams ['axes.titlesize' ],
3167
3224
'verticalalignment' : 'baseline' ,
3168
- 'horizontalalignment' : 'center'
3225
+ 'horizontalalignment' : loc . lower ()
3169
3226
}
3170
-
3171
- self .title .set_text (label )
3172
- self .title .update (default )
3227
+ title .set_text (label )
3228
+ title .update (default )
3173
3229
if fontdict is not None :
3174
- self . title .update (fontdict )
3175
- self . title .update (kwargs )
3176
- return self . title
3230
+ title .update (fontdict )
3231
+ title .update (kwargs )
3232
+ return title
3177
3233
3178
3234
def get_xlabel (self ):
3179
3235
"""
@@ -8839,6 +8895,10 @@ def get_tightbbox(self, renderer, call_axes_locator=True):
8839
8895
8840
8896
if self .title .get_visible ():
8841
8897
bb .append (self .title .get_window_extent (renderer ))
8898
+ if self ._left_title .get_visible ():
8899
+ bb .append (self ._left_title .get_window_extent (renderer ))
8900
+ if self ._right_title .get_visible ():
8901
+ bb .append (self ._right_title .get_window_extent (renderer ))
8842
8902
8843
8903
bb_xaxis = self .xaxis .get_tightbbox (renderer )
8844
8904
if bb_xaxis :
0 commit comments