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 7fd4b69

Browse filesBrowse files
authored
Merge pull request #7241 from QuLogic/categorical-bytes
Categorical support for NumPy string arrays, maybe closes #7215
2 parents 6ad368b + de03d47 commit 7fd4b69
Copy full SHA for 7fd4b69

File tree

Expand file treeCollapse file tree

2 files changed

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

2 files changed

+39
-1
lines changed

‎lib/matplotlib/category.py

Copy file name to clipboardExpand all lines: lib/matplotlib/category.py
+4-1Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,10 @@ def _set_seq_locs(self, data, value):
131131
self.locs.append(value)
132132
value += 1
133133

134+
134135
# Connects the convertor to matplotlib
135136
units.registry[str] = StrCategoryConverter()
136-
units.registry[bytes] = StrCategoryConverter()
137+
units.registry[np.str_] = StrCategoryConverter()
137138
units.registry[six.text_type] = StrCategoryConverter()
139+
units.registry[bytes] = StrCategoryConverter()
140+
units.registry[np.bytes_] = StrCategoryConverter()

‎lib/matplotlib/tests/test_category.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_category.py
+35Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,41 @@ def test_plot_1d_missing(self):
186186

187187
self.axis_test(ax.yaxis, self.dmticks, self.dmlabels, self.dmunit_data)
188188

189+
@cleanup
190+
@pytest.mark.usefixtures("data")
191+
@pytest.mark.parametrize("bars",
192+
[['a', 'b', 'c'],
193+
[b'a', b'b', b'c'],
194+
np.array([b'a', b'b', b'c'])],
195+
ids=['string list', 'bytes list',
196+
'bytes ndarray'])
197+
def test_plot_bytes(self, bars):
198+
counts = np.array([4, 6, 5])
199+
200+
fig, ax = plt.subplots()
201+
ax.bar(bars, counts)
202+
fig.canvas.draw()
203+
204+
self.axis_test(ax.xaxis, self.dticks, self.dlabels, self.dunit_data)
205+
206+
@cleanup
207+
@pytest.mark.parametrize("bars",
208+
[['1', '11', '3'],
209+
np.array(['1', '11', '3']),
210+
[b'1', b'11', b'3'],
211+
np.array([b'1', b'11', b'3'])],
212+
ids=['string list', 'string ndarray',
213+
'bytes list', 'bytes ndarray'])
214+
def test_plot_numlike(self, bars):
215+
counts = np.array([4, 6, 5])
216+
217+
fig, ax = plt.subplots()
218+
ax.bar(bars, counts)
219+
fig.canvas.draw()
220+
221+
unitmap = MockUnitData([('1', 0), ('11', 1), ('3', 2)])
222+
self.axis_test(ax.xaxis, [0, 1, 2], ['1', '11', '3'], unitmap)
223+
189224
@cleanup
190225
@pytest.mark.usefixtures("data", "missing_data")
191226
def test_plot_2d(self):

0 commit comments

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