Matplotlib 三维图像 入门

开始

import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure()  # 创建一个画板
ax = Axes3D(fig)  # 转换为3维图像

线图

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

fig = plt.figure()
ax = Axes3D(fig)

theta = np.linspace(-4 * np.pi, 4 * np.pi, 100)
z = np.linspace(-2, 2, 100)  # 设置z值
r = z**2 + 1
x = r * np.sin(theta)  # 设置x值
y = r * np.cos(theta)  # 设置y值

ax.plot(x, y, z)

plt.show()

点图

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

fig = plt.figure()
ax = Axes3D(fig)

xs=1
ys=1
zs=1

ax.scatter(xs, ys, zs)

plt.show()

线框图

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

fig = plt.figure()
ax = Axes3D(fig)

X, Y, Z = axes3d.get_test_data(0.05)  # 这里注意X,Y,Z都是二维数组

ax.plot_wireframe(X, Y, Z)

plt.show()

平面图

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


fig = plt.figure()
ax = Axes3D(fig)

X = np.arange(-5, 5, 0.25)
Y = np.arange(-5, 5, 0.25)
X, Y = np.meshgrid(X, Y)
R = np.sqrt(X**2 + Y**2)
Z = np.sin(R)

surf = ax.plot_surface(X, Y, Z)

参考文献:
https://matplotlib.org/tutorials/toolkits/mplot3d.html#sphx-glr-tutorials-toolkits-mplot3d-py

你可能感兴趣的:(matplotlib)