其他分享
首页 > 其他分享> > 绘制三维图

绘制三维图

作者:互联网

MATLAB/octave

x = -8:0.5:8;
y = x;
[X,Y] = meshgrid(x,y);
R = sqrt(X.^2+Y.^2)+eps;
Z = sin(R)./R;
mesh(X,Y,Z);
grid on
axis([-10 10 -10 10 -1 1])
Xlabel('x')
Ylabel('Y')
Zlabel('Z')

在这里插入图片描述
python

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

fig = plt.figure()
ax = Axes3D(fig)
X = np.arange(-4, 4, 0.25)
Y = np.arange(-4, 4, 0.25)
X, Y = np.meshgrid(X, Y)
R = np.sqrt(X ** 2 + Y ** 2)
Z = np.sin(R)
 
ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=plt.cm.hot)
ax.contourf(X, Y, Z, zdir='z', offset=-2, cmap=plt.cm.hot)
ax.set_zlim(-2, 2)
 
plt.show()

在这里插入图片描述

标签:10,plt,cm,三维图,import,np,ax,绘制
来源: https://blog.csdn.net/qq_41365597/article/details/94719669