【问题标题】:the best way to map numbers to colors from a numpy array column将数字映射到 numpy 数组列中的颜色的最佳方法
【发布时间】:2020-08-06 13:48:52
【问题描述】:

zs[:,2] 在我的例子中是数字,例如从 1 到 5。

plt.scatter(zs[:,0], zs[:,1], c=zs[:,2], alpha=0.5)

将这些数字(从 zs[:,2])映射到特定颜色的最佳方法是什么?

【问题讨论】:

标签: numpy matplotlib colors


【解决方案1】:

我通过 panda lib (How can I convert numbers to a color scale in matplotlib?) 以类似的方式做到了这一点。

def col_map(x):
    print(x)
    if x == 0.0:
        return "green"
    if x == 1.0:
        return 'red'
    else:
        return 'blue'

df = pd.DataFrame({"x":zs[:,0],"y":zs[:,1],"c":[col_map(x) for x in zs[:,2].tolist()]})
plt.scatter(df.x, df.y, color=df.c)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-12-12
    • 2016-02-01
    • 1970-01-01
    • 2017-05-19
    • 2021-08-28
    • 2010-10-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多