Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用matplotlib.pyploy为不同组制作不同颜色的散点图_Matplotlib_Scatter Plot - Fatal编程技术网

使用matplotlib.pyploy为不同组制作不同颜色的散点图

使用matplotlib.pyploy为不同组制作不同颜色的散点图,matplotlib,scatter-plot,Matplotlib,Scatter Plot,我正在尝试使用matplotlib.pyplot(作为plt导入)并使用以下命令为我的数据绘制散点图: fig = plt.figure(1, figsize = (10, 6)) plt.figure() plt.scatter(X_train_reduced[:, 0], X_train_reduced[:, 1], c = y_train, cmap = plt.cm.Paired , linewidths=10) 但它给出了这样一个错误: ValueError: 'c' argume

我正在尝试使用
matplotlib.pyplot
(作为
plt
导入)并使用以下命令为我的数据绘制散点图:

fig = plt.figure(1, figsize = (10, 6))
plt.figure()
plt.scatter(X_train_reduced[:, 0],  X_train_reduced[:, 1], c = y_train, cmap = plt.cm.Paired , linewidths=10)
但它给出了这样一个错误:

ValueError: 'c' argument must be a mpl color, a sequence of mpl colors or a sequence of numbers, not sample group
当我删除此参数时:

c = y_train
它返回绘图,但所有组的颜色相同(我有两个组)。
您知道如何修复它吗?

错误告诉您如何修复它,即通过将
c
参数设置为单个matplotlib颜色、颜色序列或数字序列,而不是“样本组”。@ImportanceOfBeingErnest:yo的意思是代替例如组“a”和“B”它们应该是0和1?是的,您将需要尽可能多的数字,因为您有分散点。