Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 61a869e

Browse filesBrowse files
committed
Merge pull request matplotlib#4766 from tacaswell/fix_py2_histlabel_unicode
FIX: fix python2 unicode compatibility
2 parents 1513333 + 6c95d26 commit 61a869e
Copy full SHA for 61a869e

File tree

Expand file treeCollapse file tree

2 files changed

+18
-1
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+18
-1
lines changed

‎lib/matplotlib/axes/_axes.py

Copy file name to clipboardExpand all lines: lib/matplotlib/axes/_axes.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6079,7 +6079,7 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None,
60796079
elif is_string_like(label):
60806080
labels = [label]
60816081
else:
6082-
labels = [str(lab) for lab in label]
6082+
labels = [six.text_type(lab) for lab in label]
60836083

60846084
for (patch, lbl) in zip_longest(patches, labels, fillvalue=None):
60856085
if patch:

‎lib/matplotlib/tests/test_axes.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_axes.py
+17Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3775,6 +3775,22 @@ def test_color_alias():
37753775
def test_numerical_hist_label():
37763776
fig, ax = plt.subplots()
37773777
ax.hist([range(15)] * 5, label=range(5))
3778+
ax.legend()
3779+
3780+
3781+
@cleanup
3782+
def test_unicode_hist_label():
3783+
fig, ax = plt.subplots()
3784+
a = (b'\xe5\xbe\x88\xe6\xbc\x82\xe4\xba\xae, ' +
3785+
b'r\xc3\xb6m\xc3\xa4n ch\xc3\xa4r\xc3\xa1ct\xc3\xa8rs')
3786+
b = b'\xd7\xa9\xd7\x9c\xd7\x95\xd7\x9d'
3787+
labels = [a.decode('utf-8'),
3788+
'hi aardvark',
3789+
b.decode('utf-8'),
3790+
]
3791+
3792+
ax.hist([range(15)] * 3, label=labels)
3793+
ax.legend()
37783794

37793795

37803796
@cleanup
@@ -3785,6 +3801,7 @@ def test_move_offsetlabel():
37853801
ax.yaxis.tick_right()
37863802
assert_equal((1, 0.5), ax.yaxis.offsetText.get_position())
37873803

3804+
37883805
@image_comparison(baseline_images=['rc_spines'], extensions=['png'],
37893806
savefig_kwarg={'dpi':40})
37903807
def test_rc_spines():

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.