開始使用免費開始

你的第一個繪圖!

把你目前學到的綜合起來,畫出你的第一張時間序列圖。你會先打好基礎:用你的資料產生時間序列圖,並為圖上的座標軸加上標籤。這能讓預期的讀者更容易閱讀與理解圖表。

matplotlib 是 Python 中最常用的繪圖函式庫,非常適合這項工作。所幸 pandas 在 Series 和 DataFrame 物件上實作了 .plot() 方法,這個方法是包覆 matplotlib.pyplot.plot() 的外層介面,能更輕鬆地產生圖表。

本練習屬於課程

使用 Python 視覺化時間序列資料

檢視課程

練習說明

  • 'date' 欄位設為 DataFrame 的索引。
  • 使用 discoveries DataFrame,以「blue」線圖繪製其中的時間序列,並指派給 ax
  • 指定圖表的 x 軸標籤為:'Date'
  • 指定圖表的 y 軸標籤為:'Number of great discoveries'

動手互動練習

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

# Set the date column as the index of your DataFrame discoveries
discoveries = ____

# Plot the time series in your DataFrame
ax = discoveries.____(____=____)

# Specify the x-axis label in your plot
____('Date')

# Specify the y-axis label in your plot
____('Number of great discoveries')

# Show plot
plt.show()
編輯並執行程式碼