加入註解
我們討論過的每個強化方式都可以一起搭配使用。 在下一個練習中,你可以在分布圖上加入註解,顯示平均租金與中位數的垂直線。
在這個例子中,已透過 sns.set_palette() 將調色盤改為 bright。
本練習屬於課程
Seaborn 資料視覺化中級
練習說明
- 建立一個圖形與座標軸。
- 繪製
fmr_1欄位的分布。 - 使用
axvline為已定義好的median與mean值各加入一條垂直線。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Create a figure and axes. Then plot the data
fig, ax = plt.subplots()
sns.histplot(df['fmr_1'], ax=ax)
# Customize the labels and limits
ax.set(____="1 Bedroom Fair Market Rent", xlim=(100,1500), title="US Rent")
# Add vertical lines for the median and mean
ax.axvline(x=____, color='m', label='Median', linestyle='--', linewidth=2)
ax.axvline(x=____, color='b', label='Mean', linestyle='-', linewidth=2)
# Show the legend and plot the data
ax.____()
plt.show()