[英]Seaborn/Matplotlib: Scatter plot with hue colours (like a heat map) for different variables in legend?
一般來說,我對 Matplotlib 和 python 非常陌生,並且想要顯示帶有顏色圖的散點圖,例如與圖例相對應的熱圖。
我的數據設置為兩個列表列表( x_list
和y_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 來做到這一點嗎?
您可以創建一個 rgb 顏色數組並作為參數傳遞給 matplotlib 的 scatter 函數
colors = [(t/100,0,0) for t in range(len(x_list))]
plt.scatter(x_list, y_list, color=colors)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.