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

Skip to content

Commit 39a007e

Browse files
committed
Almost fixed
Almost fixed Almost fixed Almost fixed Added test Added test Added test Added test
1 parent 39694f2 commit 39a007e

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

lib/matplotlib/category.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ def convert(value, unit, axis):
4040
"""Uses axis.unit_data map to encode
4141
data as floats
4242
"""
43+
value = np.atleast_1d(value)
44+
# try and update from here....
45+
if hasattr(axis.unit_data, 'update'):
46+
for val in value:
47+
if isinstance(val, six.string_types):
48+
axis.unit_data.update(val)
4349
vmap = dict(zip(axis.unit_data.seq, axis.unit_data.locs))
4450

4551
if isinstance(value, six.string_types):

lib/matplotlib/tests/test_category.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,3 +243,16 @@ def test_plot_update(self):
243243
unit_data = MockUnitData(list(zip(labels, ticks)))
244244

245245
self.axis_test(ax.yaxis, ticks, labels, unit_data)
246+
247+
def test_scatter_update(self):
248+
fig, ax = plt.subplots()
249+
250+
ax.scatter(['a', 'b'], [0., 3.])
251+
ax.scatter(['a', 'b', 'd'], [1., 2., 3.])
252+
ax.scatter(['b', 'c', 'd'], [4., 1., 2.])
253+
fig.canvas.draw()
254+
255+
labels = ['a', 'b', 'd', 'c']
256+
ticks = [0, 1, 2, 3]
257+
unit_data = MockUnitData(list(zip(labels, ticks)))
258+
self.axis_test(ax.xaxis, ticks, labels, unit_data)

0 commit comments

Comments
 (0)