1. 绘制3D曲面图
from matplotlib import pyplot as plt
import numpy as np
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=“rainbow”
plt.show()
2.绘制三维的散点图(表述一些数据点分布)
4a.mat数据地址:http blog.csdn.net/eddy_zhang/article/details/50496164
from matplotlib import pyplot as plt
import scipy.io as sio
from mpl_toolkits.mplot3d import Axes3D
matl=”4a.mat’
data=sio.loadmat(matl)
m=data[“data’]
x,y,z=m[0],m[1],m[2]
//创建一个绘图工程
ax=plt.subplot(111,project=”3D’)
//将数据点分成三部分画,在颜色上有区分度
ax.scatter(x[:1000], y[:1000], z[:1000],c=”y’ )//绘制数据点
ax.scatter(x[1000:4000], y[1000:4000], z[1000:4000],c=”r’ )//绘制数据点
ax.scatter(x[4000:], y[4000:], z[4000:],c=”g’ )//绘制数据点
ax.set_zlable(”z’)//坐标轴
ax.set_ylable(”y’)//坐标轴
ax.set_xlable(”x’)
plt.show()