@@ -932,10 +932,23 @@ def cla(self):
932932 verticalalignment = 'baseline' ,
933933 horizontalalignment = 'center' ,
934934 )
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+ )
937947
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 )
939952
940953 # the patch draws the background of the axes. we want this to
941954 # be below the other artists; the axesPatch name is
@@ -1990,6 +2003,8 @@ def draw(self, renderer=None, inframe=False):
19902003 artists .extend ([self .xaxis , self .yaxis ])
19912004 if not inframe :
19922005 artists .append (self .title )
2006+ artists .append (self ._left_title )
2007+ artists .append (self ._right_title )
19932008 artists .extend (self .tables )
19942009 if self .legend_ is not None :
19952010 artists .append (self .legend_ )
@@ -3100,6 +3115,8 @@ def get_children(self):
31003115 children .append (self .legend_ )
31013116 children .extend (self .collections )
31023117 children .append (self .title )
3118+ children .append (self ._left_title )
3119+ children .append (self ._right_title )
31033120 children .append (self .patch )
31043121 children .extend (self .spines .itervalues ())
31053122 return children
@@ -3137,43 +3154,82 @@ def pick(self, *args):
31373154
31383155 ### Labelling
31393156
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.
31503159
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.
31523163
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'
31543168
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
31573173
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
31593182
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.
31613214
3162- :meth:`text`
3163- for information on how override and the optional args work
31643215 """
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 )
31653222 default = {
31663223 'fontsize' : rcParams ['axes.titlesize' ],
31673224 'verticalalignment' : 'baseline' ,
3168- 'horizontalalignment' : 'center'
3225+ 'horizontalalignment' : loc . lower ()
31693226 }
3170-
3171- self .title .set_text (label )
3172- self .title .update (default )
3227+ title .set_text (label )
3228+ title .update (default )
31733229 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
31773233
31783234 def get_xlabel (self ):
31793235 """
@@ -8839,6 +8895,10 @@ def get_tightbbox(self, renderer, call_axes_locator=True):
88398895
88408896 if self .title .get_visible ():
88418897 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 ))
88428902
88438903 bb_xaxis = self .xaxis .get_tightbbox (renderer )
88448904 if bb_xaxis :
0 commit comments