開始使用免費開始

基本文字註解

在目前的散佈圖上,你會看到一個特別突出的點,代表 8 月觀測到的最大 SO2 值。這個點是 2013 年 8 月 11 日的 Cincinnati,但以圖中的現況你無法得知這些資訊。基本的文字註解很適合指出有趣的離群值,並補充一些背景。請加入一個基本的文字註解,說明這個 Cincinnati 的數值,讓讀者注意到這個離群點的背景。

本練習屬於課程

用 Python 改善你的資料視覺化

檢視課程

練習說明

  • 將散佈圖中繪製的資料篩選為僅包含 8 月。
  • x = 0.57y = 41 的位置加入文字註解,標示最高的 SO2 數值。
  • 將註解文字標籤設為 'Cincinnati had highest observed\nSO2 value on Aug 11, 2013'(注意換行)。
  • 將註解的字型大小改為 'large'

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Draw basic scatter plot of pollution data for August
sns.scatterplot(x = 'CO', y = 'SO2', data = pollution[pollution.month  ==  ____])

# Label highest SO2 value with text annotation
plt.text(____, ____,
         '____', 
         # Set the font to large
         fontdict = {'ha': 'left', '____': '____'})
plt.show()
編輯並執行程式碼