Featured image of post 使用 Python 與 matplotlib 繪製圖表的方法【支援 Google Colab】

使用 Python 與 matplotlib 繪製圖表的方法【支援 Google Colab】

為初學者說明如何使用 Google Colaboratory,透過 Python 的 matplotlib.pyplot 函式庫輕鬆繪製並顯示正弦波與餘弦波圖表的步驟。無須建置環境即可立即測試。

img_1.png

需要的東西

  • Google 帳號

步驟

  1. 進入 https://colab.research.google.com/
  2. 選擇「檔案」→「新增筆記本」
  3. 貼上並執行以下程式碼
1
2
3
4
5
6
7
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0, 2*np.pi, 500)
plt.plot(x, np.sin(x), label="sin curve")
plt.plot(x, np.cos(x), label="cos curve")
plt.legend() # 顯示圖例
plt.show()

執行結果

img.png

參考資料

comments powered by Disqus
使用 Hugo 建立
主題 StackJimmy 設計