使用 DataFrame.plot 设置散点图的颜色 [英] Set the color for scatter-plot with DataFrame.plot
本文介绍了使用 DataFrame.plot 设置散点图的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 python 绘制熊猫数据帧
I am using python to plot a pandas DataFrame
我这样设置绘图颜色:
allDf = pd.DataFrame({
'x':[0,1,2,4,7,6],
'y':[0,3,2,4,5,7],
'a':[1,1,1,0,0,0],
'c':['red','green','blue','red','green','blue']
},index = ['p1','p2','p3','p4','p5','p6'])
allDf.plot(kind='scatter',x='x',y='y',c='c')
plt.show()
但是它不起作用(每个点都有蓝色)
However it doesn't work (every point has a blue color)
如果我像这样改变DataFrame的定义
If I changed the definition of DataFrame like this
'c':[1,2,1,2,1,2]
出现彩色但只有黑白,我想用蓝色,红色等等...
It appears color but only black and white, I want to use blue, red and more...
推荐答案
替换为:
allDf.plot(kind='scatter',x='x',y='y',c=allDf.c)
输出:
这篇关于使用 DataFrame.plot 设置散点图的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文