我使用下面的python代码绘制了一个图表(附件)。问题是分配的颜色很难让人们分辨出每个数据点之间的差异。我想自定义色标。有人能帮忙吗?非常感谢!
import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline
x=[1,2,3,4,5,1,2,3,4,5]
y=[5,4,3,2,1,1,2,3,4,5]
z=[0.1,0.2,-0.1,0.3,0.05,0.1,-0.1,-0.5,0.25,-0.05]
df=pd.DataFrame({'x':x,'y':y,'z':z})
df.plot.scatter(x='x',y='y',c='z')
答案 0 :(得分:3)
将colormap
参数传递给df.plot()
,例如
df.plot.scatter(x='x',y='y',c='z', colormap='plasma')
来自pandas.DataFrame.plot的文档:
colormap
: str或matplotlib色彩映射对象,默认无用于从中选择颜色的Colormap。如果是string,则从matplotlib加载带有该名称的colormap。
您可以在colormaps_reference中查看matplotlib色彩图(我在上面使用过)。