Python数据分析10——使用Matplotlib绘制3D图

目录

3D立体图形

3D绘图

3D散点图

3D曲线图

3D平面图


3D立体图形

绘制三维图像主要通过 mplot3d 模块实现。

from matplotlib import pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
%matplotlib notebook

3D绘图

3D绘图与2D绘图使用的方法基本一致,不同的是,操作的对象变为了 Axes3D() 对象。

3D散点图

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

x = 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 plt
import numpy as np
from mpl_toolkits.mplot3d import Axes3D

zline = 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
               )

猜你喜欢

转载自blog.csdn.net/qq_52914337/article/details/125349135