Skip to content

Commit 22e6070

Browse files
committed
Merge pull request #1107 from pelson/non_str_label
Added %s support for labels.
2 parents 62fe17f + 20fffe1 commit 22e6070

File tree

7 files changed

+631
-10
lines changed

7 files changed

+631
-10
lines changed

lib/matplotlib/artist.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -677,13 +677,11 @@ def set_label(self, s):
677677
"""
678678
Set the label to *s* for auto legend.
679679
680-
ACCEPTS: any string
680+
ACCEPTS: string or anything printable with '%s' conversion.
681681
"""
682-
self._label = s
682+
self._label = '%s' % (s, )
683683
self.pchanged()
684684

685-
686-
687685
def get_zorder(self):
688686
"""
689687
Return the :class:`Artist`'s zorder.

lib/matplotlib/colorbar.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ def set_label(self, label, **kw):
401401
'''
402402
Label the long axis of the colorbar
403403
'''
404-
self._label = label
404+
self._label = '%s' % (label, )
405405
self._labelkw = kw
406406
self._set_label()
407407

lib/matplotlib/container.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ def set_label(self, s):
4141
"""
4242
Set the label to *s* for auto legend.
4343
44-
ACCEPTS: any string
44+
ACCEPTS: string or anything printable with '%s' conversion.
4545
"""
46-
self._label = s
46+
self._label = '%s' % (s, )
4747
self.pchanged()
4848

4949
def add_callback(self, func):
Binary file not shown.

lib/matplotlib/tests/baseline_images/test_legend/legend_various_labels.svg

Lines changed: 611 additions & 0 deletions
Loading

lib/matplotlib/tests/test_legend.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import numpy as np
22

3-
from matplotlib.testing.decorators import image_comparison, knownfailureif
3+
from matplotlib.testing.decorators import image_comparison
44
import matplotlib.pyplot as plt
5-
from nose.tools import assert_raises
6-
from numpy.testing import assert_array_equal
5+
76

87
@image_comparison(baseline_images=['legend_auto1'], tol=1.5e-3, remove_text=True)
98
def test_legend_auto1():
@@ -15,6 +14,7 @@ def test_legend_auto1():
1514
ax.plot(x, x-50, 'o', label='y=-1')
1615
ax.legend(loc=0)
1716

17+
1818
@image_comparison(baseline_images=['legend_auto2'], remove_text=True)
1919
def test_legend_auto2():
2020
'Test automatic legend placement'
@@ -24,3 +24,15 @@ def test_legend_auto2():
2424
b1 = ax.bar(x, x, color='m')
2525
b2 = ax.bar(x, x[::-1], color='g')
2626
ax.legend([b1[0], b2[0]], ['up', 'down'], loc=0)
27+
28+
29+
@image_comparison(baseline_images=['legend_various_labels'], remove_text=True)
30+
def test_various_labels():
31+
# tests all sorts of label types
32+
fig = plt.figure()
33+
ax = fig.add_subplot(121)
34+
x = np.arange(100)
35+
ax.plot(range(4), 'o', label=1)
36+
ax.plot(np.linspace(4, 4.1), 'o', label=u'D\xe9velopp\xe9s')
37+
ax.plot(range(4, 1, -1), 'o', label='__nolegend__')
38+
ax.legend(numpoints=1)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy