ValueError:颜色数组必须是二维的

时间:2016-07-02 09:26:51

标签: python matplotlib

我想绘制x1x2散点图,但颜色会根据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()

当我运行它时,它显示错误代码

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

任何想法如何解决这个问题?

0 个答案:

没有答案