Skip to content
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

Subsequent calls to plt.scatter with different categories raise ValueError #9700

Bernhard10 opened this issue Nov 6, 2017 · 3 comments


None yet
3 participants
Copy link

commented Nov 6, 2017

Bug report

Plotting with string categorical data fails, if the second call to plt.scatter contains categories not present in the first call to plt.scatter
Code for reproduction

import matplotlib.pyplot as plt
plt.scatter(["a", "b"], [0,2])
plt.scatter(["a","c"], [1,4])

Actual outcome

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "xxx/python3.6/site-packages/matplotlib/", line 3357, in scatter
    edgecolors=edgecolors, data=data, **kwargs)
  File "xxx/python3.6/site-packages/matplotlib/", line 1710, in inner
    return func(ax, *args, **kwargs)
  File "xxx/python3.6/site-packages/matplotlib/axes/", line 4010, in scatter
    x = self.convert_xunits(x)
  File "xxx/python3.6/site-packages/matplotlib/", line 191, in convert_xunits
    return ax.xaxis.convert_units(x)
  File "xxx/python3.6/site-packages/matplotlib/", line 1491, in convert_units
    ret = self.converter.convert(x, self.units, self)
  File "xxx/python3.6/site-packages/matplotlib/", line 53, in convert
    return vals.astype('float')
ValueError: could not convert string to float: 'c'

Expected outcome


Figure generated using

plt.plot(["a", "b"], [0,2], "o")
plt.plot(["a", "c"], [1,4], "o")

Using different categories for subsequent calls to plt.plot works as expected.

Matplotlib version

  • Operating system: Fedora
  • Matplotlib version: 2.1.0 (installed the manylinux binary wheel via pip)
  • Matplotlib backend: TkAgg
  • Python version: 3.6.2

@dstansby dstansby added the categorical label Nov 6, 2017

@dstansby dstansby added this to the v2.1.1 milestone Nov 6, 2017


This comment has been minimized.

Copy link

commented Nov 6, 2017

@dstansby aren't categoricals new? If this isn't a reversion, maybe this could be 2.2?


This comment has been minimized.

Copy link

commented Nov 6, 2017

Yes, but this code definitely shouldn't error(!) which is why I've put it on 2.1.1

@jklymak jklymak referenced this issue Nov 6, 2017


Fix scatterplot categorical support #9705

2 of 2 tasks complete

@jklymak jklymak self-assigned this Nov 6, 2017


This comment has been minimized.

Copy link

commented Nov 6, 2017

This is a duplicate of #9494, so I'll close this in lieu of the older Issue. Note PR #9705 seems to fix both. Thanks for the bug report; this one made it easier to see what was wrong with #9494 (for me)!

@jklymak jklymak closed this Nov 6, 2017

@jklymak jklymak added the Duplicate label Nov 6, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.