如何使用 matplotlib 中的數學方程繪製平面?


要使用 Matplotlib 中的數學方程繪製平面,我們可以執行以下步驟。

步驟

  • 設定圖形大小並調整子圖之間的和周圍的填充。

  • 使用 numpy 建立xy 資料點。

  • 使用xy,找到平面的方程 (eq)

  • 建立新圖形或啟用現有圖形。

  • 使用projection='3d' 獲取當前座標軸。

  • 使用x、yeq 資料點建立一個曲面圖。

  • 要顯示圖形,請使用Show() 方法。

示例

import numpy as np
import matplotlib.pyplot as plt

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

x = np.linspace(-10, 10, 100)
y = np.linspace(-10, 10, 100)

x, y = np.meshgrid(x, y)
eq = 0.12 * x + 0.01 * y + 1.09

fig = plt.figure()

ax = fig.gca(projection='3d')

ax.plot_surface(x, y, eq)

plt.show()

輸出

它會產生以下輸出 -

更新日期: 2021 年 10 月 08 日

7K+ 瀏覽

開啟您的職業生涯

透過完成課程來獲得認證

開始
廣告
© . All rights reserved.