@@ -237,9 +237,17 @@ def _update_bbox_to_anchor(self, loc_in_canvas):
237
237
title : str or None
238
238
The legend's title. Default is no title (``None``).
239
239
240
+ title_fontproperties : None or `matplotlib.font_manager.FontProperties` or dict
241
+ The font properties of the legend's title. If None (default), the
242
+ *title_fontsize* argument will be used if present; if *title_fontsize* is
243
+ also None, the current :rc:`legend.title_fontsize` will be used.
244
+
240
245
title_fontsize : int or {'xx-small', 'x-small', 'small', 'medium', 'large', \
241
246
'x-large', 'xx-large'}, default: :rc:`legend.title_fontsize`
242
247
The font size of the legend's title.
248
+ Note: This cannot be combined with *title_fontproperties*. If you want
249
+ to set the fontsize alongside other font properties, use the *size*
250
+ parameter in *title_fontproperties*.
243
251
244
252
borderpad : float, default: :rc:`legend.borderpad`
245
253
The fractional whitespace inside the legend border, in font-size units.
@@ -332,6 +340,7 @@ def __init__(self, parent, handles, labels,
332
340
bbox_transform = None , # transform for the bbox
333
341
frameon = None , # draw frame
334
342
handler_map = None ,
343
+ title_fontproperties = None , # properties for the legend title
335
344
):
336
345
"""
337
346
Parameters
@@ -506,11 +515,23 @@ def __init__(self, parent, handles, labels,
506
515
self ._set_loc (loc )
507
516
self ._loc_used_default = tmp # ignore changes done by _set_loc
508
517
509
- # figure out title fontsize:
510
- if title_fontsize is None :
511
- title_fontsize = mpl .rcParams ['legend.title_fontsize' ]
512
- tprop = FontProperties (size = title_fontsize )
513
- self .set_title (title , prop = tprop )
518
+ # figure out title font properties:
519
+ if title_fontsize is not None and title_fontproperties is not None :
520
+ raise ValueError (
521
+ "title_fontsize and title_fontproperties can't be specified "
522
+ "at the same time. Only use one of them. " )
523
+ title_prop_fp = FontProperties ._from_any (title_fontproperties )
524
+ if isinstance (title_fontproperties , dict ):
525
+ if "size" not in title_fontproperties :
526
+ title_fontsize = mpl .rcParams ["legend.title_fontsize" ]
527
+ title_prop_fp .set_size (title_fontsize )
528
+ elif title_fontsize is not None :
529
+ title_prop_fp .set_size (title_fontsize )
530
+ elif not isinstance (title_fontproperties , FontProperties ):
531
+ title_fontsize = mpl .rcParams ["legend.title_fontsize" ]
532
+ title_prop_fp .set_size (title_fontsize )
533
+
534
+ self .set_title (title , prop = title_prop_fp )
514
535
self ._draggable = None
515
536
516
537
# set the text color
0 commit comments