如何调整Matplotlib.Axes.scatter方法中的'c'参数?

How to adjust the 'c' parameter in the Matplotlib.Axes.scatter method?

我想用我选择的颜色图绘制散点图。

我的代码:

# Create a scatter plot.
scatter = axes[1][1].scatter(
fourth.VALP, # First value to use.
fourth['TAXP'].map(taxp_convert), # Second value.
s = fourth['WGTP'].map(MinimizeSize), # Size of each point is its WGTP value 
and minimizing the size
c = fourth.MRGP, # Color of each point is its MRGP value.
marker ='o')

结果:

但是,我希望颜色是这样的:

只知道axes.scatter中的c参数是负责颜色的,不知道怎么改成想要的颜色

您做的一切都正确。 c 参数是散点根据颜色图着色的数量。它也可以用于直接指定颜色(每点一种颜色)。

如果要更改默认颜色图,可以使用 cmap 参数。例如

plt.scatter(...., cmap="coolwarm")

会给你一个你想要的情节。 如需完整概述,请查看 colormaps_reference