Skip to content

Commit 4e93806

Browse files
committed
Added fontsize= argument to legend for consistency with other matplotlib methods/functions
1 parent 8cf1593 commit 4e93806

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

lib/matplotlib/axes.py

+6
Original file line numberDiff line numberDiff line change
@@ -4410,6 +4410,12 @@ def legend(self, *args, **kwargs):
44104410
instance. If *prop* is a dictionary, a new instance will be
44114411
created with *prop*. If *None*, use rc settings.
44124412
4413+
*fontsize*: [ size in points | 'xx-small' | 'x-small' | 'small' |
4414+
'medium' | 'large' | 'x-large' | 'xx-large' ]
4415+
Set the font size. May be either a size string, relative to
4416+
the default font size, or an absolute font size in points. This
4417+
argument is only used if prop is not specified.
4418+
44134419
*numpoints*: integer
44144420
The number of points in the legend for line
44154421

lib/matplotlib/legend.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ def __init__(self, parent, handles, labels,
134134
scatterpoints = 3, # TODO: may be an rcParam
135135
scatteryoffsets=None,
136136
prop = None, # properties for the legend texts
137+
fontsize = None, # keyword to set font size directly
137138

138139
# the following dimensions are in axes coords
139140
pad = None, # deprecated; use borderpad
@@ -174,6 +175,7 @@ def __init__(self, parent, handles, labels,
174175
================ ==================================================================
175176
loc a location code
176177
prop the font property
178+
fontsize the font size (used only if prop is not specified)
177179
markerscale the relative size of legend markers vs. original
178180
numpoints the number of points in the legend for line
179181
scatterpoints the number of points in the legend for scatter plot
@@ -214,7 +216,10 @@ def __init__(self, parent, handles, labels,
214216
Artist.__init__(self)
215217

216218
if prop is None:
217-
self.prop=FontProperties(size=rcParams["legend.fontsize"])
219+
if fontsize is not None:
220+
self.prop=FontProperties(size=fontsize)
221+
else:
222+
self.prop=FontProperties(size=rcParams["legend.fontsize"])
218223
elif isinstance(prop, dict):
219224
self.prop=FontProperties(**prop)
220225
if "size" not in prop:

0 commit comments

Comments
 (0)