【问题标题】:Seaborn/Matplotlib: Scatter plot with hue colours (like a heat map) for different variables in legend?Seaborn/Matplotlib:图例中不同变量的色相散点图(如热图)?
【发布时间】:2020-08-27 18:51:18
【问题描述】:

总的来说,我对 Matplotlib 和 python 非常陌生,并且想显示一个带有颜色图的散点图,例如hot 对应图例。

我的数据设置为两个列表列表(x_listy_list),每个长度为 100。

for i in x_list:
   x_list[i] = # list of data corresponding to a function where T = i

我有一个这样的情节,其中每种颜色都是 T 的值:

for T in range(100):
    x = x_list[T]
    y = y_list[T]
    
    plt.scatter(x, y, label="T{}".format(T))

理想情况下,我希望它在 seaborn 模块中看起来像这样

根据 T 的值,分配给每个点的颜色是颜色图渐变。

我可以用 Matplotlib 中的颜色图 cm 做到这一点吗?

【问题讨论】:

    标签: python matplotlib


    【解决方案1】:

    您可以创建一个 rgb 颜色数组并作为参数传递给 matplotlib 的 scatter 函数

    colors = [(t/100,0,0) for t in range(len(x_list))] 
    plt.scatter(x_list, y_list, color=colors)
    

    【讨论】:

      猜你喜欢
      • 2016-12-14
      • 2017-05-09
      • 1970-01-01
      • 2013-06-29
      • 2022-01-21
      • 1970-01-01
      • 2018-01-27
      • 1970-01-01
      相关资源
      最近更新 更多