加入標籤與圖例

Python 的資料科學入門

Hillary Green-Lerman

Lead Data Scientist, Looker

我們剛畫了什麼?

from matplotlib import pyplot as plt

plt.plot(ransom.letter,
         ransom.frequency)

plt.show()

Python 的資料科學入門

座標軸與標題標籤

plt.xlabel("Letter")
plt.ylabel("Frequency")
plt.title("Ransom Note Letters")

在 plt.show() 之前設定標籤皆可

Python 的資料科學入門

圖例

plt.plot(aditya.days,
         aditya.cases,
         label="Aditya")
plt.plot(deshaun.days,
         deshaun.cases,
         label="Deshaun")
plt.plot(mengfei.days,
         mengfei.cases,
         label="Mengfei")
plt.legend()

Python 的資料科學入門

任意文字標註

plt.text(xcoord,
    ycoord,
    "Text Message")
plt.text(5,
    9,
    "Unusually low H frequency!")

Python 的資料科學入門

調整文字

  • 變更字型大小
    plt.title("Plot title", fontsize=20)
    
  • 變更字色
    plt.legend(color="green")
    

https://en.wikipedia.org/wiki/Web_colors

Python 的資料科學入門

一起來練習吧!

Python 的資料科學入門

Preparing Video For Download...