使用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?是的,您将需要尽可能多的数字,因为您有分散点。