開始使用免費開始

匯入 matplotlib 與 pyplot

Pyplot 是熱門視覺化套件 Matplotlib 中的一組函式。它的功能可以操作圖表的各個元素,例如建立圖形、建立繪圖區、繪製折線、加入標籤等等。現在,讓我們使用 pyplotplot() 函式,畫出一張呈現某公司股價成長的虛線圖。記得,你可以用參數 color 來改變線條顏色,用參數 linestyle 來改變線型。

在你的工作區中已提供兩個串列:days(代表公司上市以來的天數)與 prices(代表對應當天的股價)。

本練習屬於課程

Python 金融入門

檢視課程

練習說明

  • 有選擇性地從 matplotlib 匯入 pyplot 模組並命名為 plt
  • days 畫在 x 軸、prices 畫在 y 軸,並以紅色虛線呈現。
  • 使用 show() 函式顯示圖表。

動手互動練習

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

# Import matplotlib.pyplot with the alias plt
import matplotlib.pyplot as ____

# Plot the price of stock over time
plt.plot(____, ____, color="____", linestyle="____")

# Display the plot
plt.____()
編輯並執行程式碼