因为我刚开始使用python进行数据分析,所以我想通过教程和从其他人那里调整工作代码来提高我的技能。
目前,我正在处理fruit_data_with_colors数据集,并希望了解python代码,可在以下站点获得:
开头的一个示例显示了不同数字输入变量(高度、宽度、质量、颜色)的散射矩阵。使用上述代码,绘制的图像中的颜色为紫色、棕色、黄色和黑色。我想把这个换成更有吸引力的颜色(例如红色,蓝色,绿色,黑色)。
我查看了matplotlib的文档,认为我应该调整代码的"c = y"部分。gen/matplotlib.pyplot.tal.html
尝试"c = ['blue']"效果很好,但是如果我以"c = ['blue', 'red']"的形式添加了另一种颜色,就会发生错误:
ValueError: 'c' argument has 2 elements, which is not acceptable for use with 'x' with size 59, 'y' with size 59.
X = fruits[feature_names]
y = fruits['fruit_label']
from matplotlib import cm
cmap = cm.get_cmap('gnuplot')
scatter = pd.scatter_matrix(X, c = y, marker = 'o', s=40, hist_kwds={'bins':15}, figsize=(9,9), cmap = cmap)
plt.suptitle('Scatter-matrix for each input variable')
plt.savefig('fruits_scatter_matrix')```https://stackoverflow.com/questions/57771719
复制相似问题