[英]How can I change the color of my scatter plot points based on a "color" column in my dataset in plotly (python)?
[英]Color scatter plot points based on a value in third column?
我目前正在根據兩列數據繪制散點圖。 但是,我想基於第三列中的類標簽為數據點着色。
我的第三列中的標簽是1,2或3.我如何根據第三列中的值為散點圖顏色着色?
plt.scatter(waterUsage['duration'],waterUsage['water_amount'])
plt.xlabel('Duration (seconds)')
plt.ylabel('Water (gallons)')
scatter
函數愉快地采用表示顏色的數字列表。 如果需要,您也可以使用色彩映射(但您不需要):
plt.scatter(waterUsage['duration'], waterUsage['water_amount'],\
c=waterUsage['third_column'], cmap=plt.cm.autumn)
在詞典中添加另一個條目“color”
def addcolor(b):
a=b
for x in range(len(a['third_column'])):
if a['third_column'][x]==1: a['color'][x]='rosybrown'
elif a['third_column'][x]==2: a['color'][x]='papayawhip'
elif a['third_column'][x]==3: a['color'][x]='chartreuse'
return a
waterUsage = addcolor(waterUsage)
plt.scatter(waterUsage['duration'],
waterUsage['water_amount'],
c=waterUsage['color'])
matplotlib接受灰度,rgb,十六進制和html顏色:
http://matplotlib.org/api/colors_api.html
html顏色列表,按組:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.