Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 570fe32

Browse files
committed
DOC: expand legend entry
1 parent b623084 commit 570fe32

1 file changed

Lines changed: 69 additions & 13 deletions

File tree

doc/users/dflt_style_changes.rst

Lines changed: 69 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,75 @@ The default math font when using the built-in math rendering engine
490490
``mathtext.fontset`` to ``cm``. This change has no effect if the
491491
TeX backend is used (i.e. ``text.usetex`` is ``True``).
492492

493+
Legends
494+
=======
495+
496+
- By default, the number of points displayed in a legend is now 1.
497+
- The default legend location is ``best``, so the legend will be
498+
automatically placed in a location to obscure the least amount of
499+
data possible.
500+
- The legend now has rounded corners by default.
501+
- The legend defaults now include rounded corners, a lighter
502+
boundary, and partially transparent boundary and background.
503+
504+
.. plot::
505+
506+
import matplotlib as mpl
507+
import numpy as np
508+
import matplotlib.pyplot as plt
509+
import numpy as np
510+
511+
def demo(ax, rcparams, title):
512+
np.random.seed(2)
513+
N = 25
514+
with mpl.rc_context(rc=rcparams):
515+
x = range(N)
516+
y = np.cumsum(np.random.randn(N) )
517+
ln, = ax.plot(x, y, marker='s',
518+
linestyle='-', label='plot')
519+
ax.fill_between(x, y, 0, label='fill', alpha=.5, color=ln.get_color())
520+
ax.scatter(N*np.random.rand(N), np.random.rand(N), label='scatter')
521+
ax.set_title(title)
522+
ax.legend()
523+
524+
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(6, 3), tight_layout=True)
525+
526+
classic_rc = {'legend.fancybox': False,
527+
'legend.numpoints': 2,
528+
'legend.scatterpoints': 3,
529+
'legend.framealpha': None,
530+
'legend.edgecolor': 'inherit',
531+
'legend.loc': 'upper right',
532+
'legend.fontsize': 'large',
533+
}
534+
535+
demo(ax1, classic_rc, 'classic')
536+
demo(ax2, {}, 'v2.0')
537+
538+
539+
The previous defaults can be restored by setting::
540+
541+
mpl.rcParams['legend.fancybox'] = False
542+
mpl.rcParams['legend.loc'] = 'upper right'
543+
mpl.rcParams['legend.numpoints'] = 2
544+
mpl.rcParams['legend.fontsize'] = 'large'
545+
mpl.rcParams['legend.framealpha'] = None
546+
mpl.rcParams['legend.scatterpoints'] = 3
547+
mpl.rcParams['legend.edgecolor'] = 'inherit'
548+
549+
550+
or by setting::
551+
552+
legend.fancybox : False
553+
legend.loc : upper right
554+
legend.numpoints : 2 # the number of points in the legend line
555+
legend.fontsize : large
556+
legend.framealpha : None # opacity of of legend frame
557+
legend.scatterpoints : 3 # number of scatter points
558+
legend.edgecolor : inherit # legend edge color (when None inherits from axes.facecolor)
559+
560+
in your :file:`matplotlibrc` file.
561+
493562

494563
TEMPORARY NOTES TOM IS KEEPING IN THE SOURCE SO THEY DO NOT GET LOST
495564
====================================================================
@@ -550,19 +619,6 @@ Dates
550619
``%x`` and ``%X`` date formats may be of particular interest to
551620
format dates based on the current locale.
552621

553-
Legends
554-
=======
555-
556-
- By default, the number of points displayed in a legend is now 1.
557-
558-
- The default legend location is ``best``, so the legend will be
559-
automatically placed in a location to obscure the least amount of
560-
data possible.
561-
562-
- The legend now has rounded corners by default.
563-
564-
- "The legend defaults now include rounded corners, a lighter
565-
boundary, and partially transparent boundary and background."
566622

567623
mplot3d
568624
=======

0 commit comments

Comments
 (0)