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

Skip to content

FIX: fix python2 unicode compatibility #4766

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 23, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
17 changes: 17 additions & 0 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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():
Expand Down