目录
3D立体图形
3D绘图
3D散点图
3D曲线图
3D平面图
3D立体图形
绘制三维图像主要通过 mplot3d 模块实现。
from matplotlib import pyplot as pltfrom mpl_toolkits.mplot3d import Axes3D%matplotlib notebook
3D绘图
3D绘图与2D绘图使用的方法基本一致,不同的是,操作的对象变为了 Axes3D() 对象。
3D散点图
from matplotlib import pyplot as pltimport numpy as npfrom mpl_toolkits.mplot3d import Axes3Dx = np.random.rand(100)y = np.random.rand(100)z = np.random.rand(100)fig = plt.figure()ax = Axes3D(fig)ax.scatter(x,y,z,s=10,color="r",marker='o')plt.show()
3D曲线图
from matplotlib import pyplot as pltimport numpy as npfrom mpl_toolkits.mplot3d import Axes3Dzline = np.linspace(0,15,1000)xline = np.sin(zline)yline = np.cos(zline)fig = plt.figure()ax = Axes3D(fig)ax.plot(xline,yline,zline)plt.show()
3D平面图
x = [1,2,3,4]y = [1,2,3,4]X, Y = np.meshgrid(x, y)# 创建画布fig = plt.figure()# 创建3D坐标系ax = Axes3D(fig)ax.plot_surface(X,Y,Z=X+Y)