使用自訂的類別型調色盤
當你的折線圖包含許多類別時,謹慎選擇調色盤就很關鍵。許多預設調色盤的色相彼此太接近,分散到細長的折線上時很難區分。ColorBrewer 的調色盤就是為此設計,盡量讓各色彼此區隔明顯。
在這個練習中,你將繪製各城市在 2013 年的 O3 值折線圖,並以城市來編碼每條線的顏色。你會使用 ColorBrewer 的 'Set2' 調色盤,讓配色比預設更清楚易讀。
本練習屬於課程
用 Python 改善你的資料視覺化
練習說明
- 查詢 2013 年 1 月的資料。
- 以城市來編碼線條的顏色。
- 將調色盤改為 ColorBrewer 的
'Set2'。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Filter our data to Jan 2013
pollution_jan13 = pollution.query('year == ____ & month == ____')
# Color lines by the city and use custom ColorBrewer palette
sns.lineplot(x = "day",
y = "CO",
____ = "____",
____ = "____",
linewidth = 3,
data = pollution_jan13)
plt.show()