Matplotlib绘制正余弦曲面图

Matplotlib绘制正弦曲面图

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

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

x = np.arange(-4, 4, 0.25)
y = np.arange(-4, 4, 0.25)
x, y = np.meshgrid(x, y)
distance = np.sqrt(x**2 + y**2)
z = 1.5*np.sin(distance)+0.5

ax.plot_surface(x, y, z, rstride=1, cstride=1, cmap=plt.get_cmap('rainbow'))
ax.contourf(x, y, z, zdir='z', offset=-2)
ax.set_zlim(-2, 3)

plt.show()

正弦曲面成品图

在这里插入图片描述

Matplotlib绘制余弦曲面图

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

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

x = np.arange(-4, 4, 0.25)
y = np.arange(-4, 4, 0.25)
x, y = np.meshgrid(x, y)
distance = np.sqrt(x**2 + y**2)
z = 1.5*np.cos(distance)+0.5

ax.plot_surface(x, y, z, rstride=1, cstride=1, cmap=plt.get_cmap('rainbow'))
ax.contourf(x, y, z, zdir='z', offset=-2)
ax.set_zlim(-2, 3)

plt.show()

余弦曲面成品图

在这里插入图片描述

发布了505 篇原创文章 · 获赞 999 · 访问量 19万+

猜你喜欢

转载自blog.csdn.net/weixin_43896318/article/details/104294538