diff --git a/lib/matplotlib/artist.py b/lib/matplotlib/artist.py index 072b44bf5136..51c2ebc4b266 100644 --- a/lib/matplotlib/artist.py +++ b/lib/matplotlib/artist.py @@ -673,13 +673,11 @@ def set_label(self, s): """ Set the label to *s* for auto legend. - ACCEPTS: any string + ACCEPTS: string or anything printable with '%s' conversion. """ - self._label = s + self._label = '%s' % (s, ) self.pchanged() - - def get_zorder(self): """ Return the :class:`Artist`'s zorder. diff --git a/lib/matplotlib/colorbar.py b/lib/matplotlib/colorbar.py index e476c5a539b3..e600828d9712 100644 --- a/lib/matplotlib/colorbar.py +++ b/lib/matplotlib/colorbar.py @@ -401,7 +401,7 @@ def set_label(self, label, **kw): ''' Label the long axis of the colorbar ''' - self._label = label + self._label = '%s' % (label, ) self._labelkw = kw self._set_label() diff --git a/lib/matplotlib/container.py b/lib/matplotlib/container.py index cb8a58028e39..a2809108d9c6 100644 --- a/lib/matplotlib/container.py +++ b/lib/matplotlib/container.py @@ -41,9 +41,9 @@ def set_label(self, s): """ Set the label to *s* for auto legend. - ACCEPTS: any string + ACCEPTS: string or anything printable with '%s' conversion. """ - self._label = s + self._label = '%s' % (s, ) self.pchanged() def add_callback(self, func): diff --git a/lib/matplotlib/tests/baseline_images/test_legend/legend_various_labels.pdf b/lib/matplotlib/tests/baseline_images/test_legend/legend_various_labels.pdf new file mode 100644 index 000000000000..2dd7b3df0a83 Binary files /dev/null and b/lib/matplotlib/tests/baseline_images/test_legend/legend_various_labels.pdf differ diff --git a/lib/matplotlib/tests/baseline_images/test_legend/legend_various_labels.png b/lib/matplotlib/tests/baseline_images/test_legend/legend_various_labels.png new file mode 100644 index 000000000000..aee83850ecae Binary files /dev/null and b/lib/matplotlib/tests/baseline_images/test_legend/legend_various_labels.png differ diff --git a/lib/matplotlib/tests/baseline_images/test_legend/legend_various_labels.svg b/lib/matplotlib/tests/baseline_images/test_legend/legend_various_labels.svg new file mode 100644 index 000000000000..3805a4cda425 --- /dev/null +++ b/lib/matplotlib/tests/baseline_images/test_legend/legend_various_labels.svg @@ -0,0 +1,611 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/lib/matplotlib/tests/test_legend.py b/lib/matplotlib/tests/test_legend.py index 92acc26fece6..2dc002cef160 100644 --- a/lib/matplotlib/tests/test_legend.py +++ b/lib/matplotlib/tests/test_legend.py @@ -1,9 +1,8 @@ import numpy as np -from matplotlib.testing.decorators import image_comparison, knownfailureif +from matplotlib.testing.decorators import image_comparison import matplotlib.pyplot as plt -from nose.tools import assert_raises -from numpy.testing import assert_array_equal + @image_comparison(baseline_images=['legend_auto1'], tol=1.5e-3, remove_text=True) def test_legend_auto1(): @@ -15,6 +14,7 @@ def test_legend_auto1(): ax.plot(x, x-50, 'o', label='y=-1') ax.legend(loc=0) + @image_comparison(baseline_images=['legend_auto2'], remove_text=True) def test_legend_auto2(): 'Test automatic legend placement' @@ -24,3 +24,15 @@ def test_legend_auto2(): b1 = ax.bar(x, x, color='m') b2 = ax.bar(x, x[::-1], color='g') ax.legend([b1[0], b2[0]], ['up', 'down'], loc=0) + + +@image_comparison(baseline_images=['legend_various_labels'], remove_text=True) +def test_various_labels(): + # tests all sorts of label types + fig = plt.figure() + ax = fig.add_subplot(121) + x = np.arange(100) + ax.plot(range(4), 'o', label=1) + ax.plot(np.linspace(4, 4.1), 'o', label=u'D\xe9velopp\xe9s') + ax.plot(range(4, 1, -1), 'o', label='__nolegend__') + ax.legend(numpoints=1)