如何更改顏色並在 Python Matplotlib 曲面圖中新增網格線?


若要更改顏色並在 Python 曲面圖中新增網格線,我們可以採取以下步驟 −

  • 設定圖形大小,並調整子圖之間及周圍的邊距。

  • 使用 numpy 建立 xyh 資料點。

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

  • 獲取 3D 軸物件,且 figure(來自步驟 3)。

  • 建立一個曲面圖,帶橙色、邊緣顏色和線寬。

示例

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

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

x = np.arange(-5, 5, 0.25)
y = np.arange(-5, 5, 0.25)

x, y = np.meshgrid(x, y)
h = np.sin(x)*np.cos(y)

fig = plt.figure()

ax = Axes3D(fig)
ax.plot_surface(x, y, h, rstride=10, cstride=10, color='orangered', edgecolors='yellow', lw=0.6)

plt.show()

輸出

更新時間:23-Sep-2021

1000+ 瀏覽

開啟你的 職業生涯

完成課程,獲得認證

開始
廣告