自訂你的圖表

Matplotlib 資料視覺化入門

Ariel Rokem

Data Scientist

自訂資料外觀

ax.plot(seattle_weather["MONTH"], 
        seattle_weather["MLY-PRCP-NORMAL"])
plt.show()

Matplotlib 資料視覺化入門

加入標記

ax.plot(seattle_weather["MONTH"], 
        seattle_weather["MLY-PRCP-NORMAL"], 
        marker="o")
plt.show()

Matplotlib 資料視覺化入門

選擇標記樣式

ax.plot(seattle_weather["MONTH"], 
        seattle_weather["MLY-PRCP-NORMAL"], 
        marker="v")
plt.show()

https://matplotlib.org/api/markers_api.html

Matplotlib 資料視覺化入門

設定線型

fig, ax = plt.subplots()
ax.plot(seattle_weather["MONTH"], 
        seattle_weather["MLY-TAVG-NORMAL"],
        marker="v", linestyle="--")
plt.show()

Matplotlib 資料視覺化入門

用線型移除連線

fig, ax = plt.subplots()
ax.plot(seattle_weather["MONTH"], 
        seattle_weather["MLY-TAVG-NORMAL"],
        marker="v", linestyle="None")
plt.show()

Matplotlib 資料視覺化入門

選擇顏色

fig, ax = plt.subplots()
ax.plot(seattle_weather["MONTH"], 
        seattle_weather["MLY-TAVG-NORMAL"],
        marker="v", linestyle="--", color="r")
plt.show()

Matplotlib 資料視覺化入門

自訂座標軸標籤

ax.set_xlabel("Time (months)")
plt.show()

Matplotlib 資料視覺化入門

設定 y 軸標籤

ax.set_xlabel("Time (months)")
ax.set_ylabel("Average temperature (Fahrenheit degrees)")
plt.show()

Matplotlib 資料視覺化入門

加入標題

ax.set_title("Weather in Seattle")
plt.show()

Matplotlib 資料視覺化入門

一起來練習吧!

Matplotlib 資料視覺化入門

Preparing Video For Download...