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

Skip to content

Commit c721a15

Browse files
jmehneJulian Mehne
authored andcommitted
Various documentation changes
- Add what's new entry - Update legend guide - Document HandlerTuple's default values
1 parent 609571e commit c721a15

3 files changed

Lines changed: 27 additions & 2 deletions

File tree

doc/users/legend_guide.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,21 @@ following example demonstrates combining two legend keys on top of one another:
198198

199199
plt.legend([red_dot, (red_dot, white_cross)], ["Attr A", "Attr A+B"])
200200

201+
The :class:`~matplotlib.legend_handler.HandlerTuple` class can also be used to
202+
assign several legend keys to the same entry:
203+
204+
.. plot::
205+
:include-source:
206+
207+
import matplotlib.pyplot as plt
208+
from matplotlib.legend_handler import HandlerLine2D, HandlerTuple
209+
210+
p1, = plt.plot([1, 2.5, 3], 'r-d')
211+
p2, = plt.plot([3, 2, 1], 'k-o')
212+
213+
l = plt.legend([(p1, p2)], ['Two keys'], numpoints=1,
214+
handler_map={tuple: HandlerTuple(ndivide=0)})
215+
201216

202217
Implementing a custom legend handler
203218
------------------------------------
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Multiple legend keys for legend entries
2+
---------------------------------------
3+
4+
A legend entry can now contain more than one legend key. The extended
5+
``HandlerTuple`` class now accepts two parameters: ``ndivide`` divides the
6+
legend area in the specified number of sections; ``pad`` changes the padding
7+
between the legend keys.
8+
9+
.. plot:: mpl_examples/pylab_examples/legend_demo6.py
10+

lib/matplotlib/legend_handler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -577,12 +577,12 @@ class HandlerTuple(HandlerBase):
577577
578578
ndivide : int, optional
579579
The number of sections to divide the legend area into. If 0,
580-
use the length of the input tuple.
580+
use the length of the input tuple. Default is 1.
581581
582582
583583
pad : float, optional
584584
If None, fall back to `legend.borderpad` as the default.
585-
In units of fraction of font size.
585+
In units of fraction of font size. Default is None.
586586
587587
588588

0 commit comments

Comments
 (0)