【问题标题】:How to adjust the 'c' parameter in the Matplotlib.Axes.scatter method?如何调整 Matplotlib.Axes.scatter 方法中的“c”参数?
【发布时间】:2017-06-30 14:10:42
【问题描述】:

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

我的代码:

# 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参数是负责颜色的,不知道怎么改成想要的颜色。

【问题讨论】:

    标签: python matplotlib scatter-plot


    【解决方案1】:

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

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

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

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

    【讨论】:

    • 是的,做到了!你能解释一下 scatter 函数中'c'参数的用途吗?
    • 我更新了答案。如果这还不够,您可能想说出您对此不了解的具体内容。
    猜你喜欢
    • 2021-08-31
    • 1970-01-01
    • 2021-04-30
    • 2018-09-11
    • 1970-01-01
    • 2019-01-12
    • 2010-10-11
    • 1970-01-01
    • 2014-08-03
    相关资源
    最近更新 更多