使用 Matplotlib 中的 pyplot.plot() 繪製引數化曲線


要使用 **pyplot.plot()** 繪製引數化曲線,我們可以採取以下步驟 −

  • 設定影像大小,並調整子圖之間和周圍的邊距。
  • 初始化一個變數 N,表示取樣數。
  • 使用 numpy 建立 t、r、xy 資料點。
  • 建立一個影像和一組子圖。
  • 使用 **plot()** 方法繪製 x 和 y 資料點。
  • 要顯示影像,請使用 **show()** 方法。

示例

import numpy as np
import matplotlib.pyplot as plt

plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True

N = 400
t = np.linspace(0, 2 * np.pi, N)
r = 0.5 + np.cos(t)
x, y = r * np.cos(t), r * np.sin(t)
fig, ax = plt.subplots()
ax.plot(x, y)

plt.show()

輸出

更新於: 09-Jun-2021

3K+ 瀏覽量

啟動你的 事業

完成課程即可獲得證書

開始
廣告
© . All rights reserved.