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

Skip to content

Commit 9f10618

Browse files
committed
Use None as sentinel value for ndivide.
1 parent d255e50 commit 9f10618

4 files changed

Lines changed: 8 additions & 8 deletions

File tree

doc/users/legend_guide.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ assign several legend keys to the same entry:
211211
p2, = plt.plot([3, 2, 1], 'k-o')
212212

213213
l = plt.legend([(p1, p2)], ['Two keys'], numpoints=1,
214-
handler_map={tuple: HandlerTuple(ndivide=0)})
214+
handler_map={tuple: HandlerTuple(ndivide=None)})
215215

216216

217217
Implementing a custom legend handler

examples/pylab_examples/legend_demo6.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# and using a generic handler map (which would be used for any additional
1717
# tuples of handles like (p1, p3)).
1818
l = ax1.legend([(p1, p3), p2], ['two keys', 'one key'], scatterpoints=1,
19-
numpoints=1, handler_map={tuple: HandlerTuple(ndivide=0)})
19+
numpoints=1, handler_map={tuple: HandlerTuple(ndivide=None)})
2020

2121
# Second plot: plot two bar charts on top of each other and change the padding
2222
# between the legend keys
@@ -29,7 +29,7 @@
2929

3030
# Treat each legend entry differently by using specific `HandlerTuple`s
3131
l = ax2.legend([(rpos, rneg), (rneg, rpos)], ['pad!=0', 'pad=0'],
32-
handler_map={(rpos, rneg): HandlerTuple(ndivide=0),
33-
(rneg, rpos): HandlerTuple(ndivide=0, pad=0.)})
32+
handler_map={(rpos, rneg): HandlerTuple(ndivide=None),
33+
(rneg, rpos): HandlerTuple(ndivide=None, pad=0.)})
3434

3535
plt.show()

lib/matplotlib/legend_handler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ class HandlerTuple(HandlerBase):
576576
----------
577577
578578
ndivide : int, optional
579-
The number of sections to divide the legend area into. If 0,
579+
The number of sections to divide the legend area into. If None,
580580
use the length of the input tuple. Default is 1.
581581
582582
@@ -599,7 +599,7 @@ def create_artists(self, legend, orig_handle,
599599

600600
handler_map = legend.get_legend_handler_map()
601601

602-
if self._ndivide == 0:
602+
if self._ndivide is None:
603603
ndivide = len(orig_handle)
604604
else:
605605
ndivide = self._ndivide

lib/matplotlib/tests/test_legend.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ def test_multiple_keys():
8989
p3, = ax.plot([3, 4, 5], '-d')
9090
ax.legend([(p1, p2), (p2, p1), p3], ['two keys', 'pad=0', 'one key'],
9191
numpoints=1,
92-
handler_map={(p1, p2): HandlerTuple(ndivide=0),
93-
(p2, p1): HandlerTuple(ndivide=0, pad=0)})
92+
handler_map={(p1, p2): HandlerTuple(ndivide=None),
93+
(p2, p1): HandlerTuple(ndivide=None, pad=0)})
9494

9595

9696
@image_comparison(baseline_images=['rgba_alpha'],

0 commit comments

Comments
 (0)