如何改变Python Matplotlib表面图的颜色并添加网格线?
要改变Python表面图的颜色并添加网格线,可以执行以下步骤:
- 设置图形的大小并调整子图之间和周围的填充。
-
使用NumPy创建 x,y和h 数据点。
-
创建一个新图或激活现有图。
-
获取3D坐标轴对象,带有获取到的 图 (从步骤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()