如何自定义python数据帧散点图颜色?

2024-07-08 15:09:53 发布

您现在位置:Python中文网/ 问答频道 /正文

我用下面的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')

enter image description here


Tags: 数据代码importpandasdfmatplotlib颜色as
1条回答
网友
1楼 · 发布于 2024-07-08 15:09:53

colormap参数传递给df.plot(),例如

df.plot.scatter(x='x',y='y',c='z', colormap='plasma')

enter image description here

来自pandas.DataFrame.plot的文档:

colormap : str or matplotlib colormap object, default None

Colormap to select colors from. If string, load colormap with that name from matplotlib.

您可以在colormaps_reference中查看matplotlib colormaps(正如我上面使用的)。在

相关问题 更多 >

    热门问题