1

I would like to plot x1 and x2 scatter graph but the color will be different based on the class which is y

y = np.array(df['class'])
x1 = np.array(df['clump_thickness'])
x2 = np.array(df['bland_chrom'])

plt.scatter(x1,x2, color = y)
plt.show()

when I run this it shows me error code of

Traceback (most recent call last):
  File "try.py", line 43, in <module>
    plt.scatter(x1,x2, color = y)
  File "C:\Anaconda2\lib\site-packages\matplotlib\pyplot.py", line 3251, in scatter
    edgecolors=edgecolors, data=data, **kwargs)
  File "C:\Anaconda2\lib\site-packages\matplotlib\__init__.py", line 1811, in inner
    return func(ax, *args, **kwargs)
  File "C:\Anaconda2\lib\site-packages\matplotlib\axes\_axes.py", line 3893, in scatter
    alpha=alpha
  File "C:\Anaconda2\lib\site-packages\matplotlib\collections.py", line 831, in __init__
    Collection.__init__(self, **kwargs)
  File "C:\Anaconda2\lib\site-packages\matplotlib\collections.py", line 116, in __init__
    self.set_edgecolor(edgecolors)
  File "C:\Anaconda2\lib\site-packages\matplotlib\collections.py", line 660, in set_edgecolor
    self._edgecolors = mcolors.colorConverter.to_rgba_array(c, self._alpha)
  File "C:\Anaconda2\lib\site-packages\matplotlib\colors.py", line 403, in to_rgba_array
    raise ValueError("Color array must be two-dimensional")
ValueError: Color array must be two-dimensional

any idea how to fix this?

Serenity
  • 35,289
  • 20
  • 120
  • 115
gllow
  • 63
  • 2
  • 8

0 Answers0