diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index 28765cb49d92..01c94be87190 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -6079,7 +6079,7 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None, elif is_string_like(label): labels = [label] else: - labels = [str(lab) for lab in label] + labels = [six.text_type(lab) for lab in label] for (patch, lbl) in zip_longest(patches, labels, fillvalue=None): if patch: diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index a152a4a6d562..a2d0cad714b8 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -3775,6 +3775,22 @@ def test_color_alias(): def test_numerical_hist_label(): fig, ax = plt.subplots() ax.hist([range(15)] * 5, label=range(5)) + ax.legend() + + +@cleanup +def test_unicode_hist_label(): + fig, ax = plt.subplots() + a = (b'\xe5\xbe\x88\xe6\xbc\x82\xe4\xba\xae, ' + + b'r\xc3\xb6m\xc3\xa4n ch\xc3\xa4r\xc3\xa1ct\xc3\xa8rs') + b = b'\xd7\xa9\xd7\x9c\xd7\x95\xd7\x9d' + labels = [a.decode('utf-8'), + 'hi aardvark', + b.decode('utf-8'), + ] + + ax.hist([range(15)] * 3, label=labels) + ax.legend() @cleanup @@ -3785,6 +3801,7 @@ def test_move_offsetlabel(): ax.yaxis.tick_right() assert_equal((1, 0.5), ax.yaxis.offsetText.get_position()) + @image_comparison(baseline_images=['rc_spines'], extensions=['png'], savefig_kwarg={'dpi':40}) def test_rc_spines():