matplotlib 绘制 3D图像
程序员文章站
2022-03-02 08:18:29
...
'''
绘制3D散点图
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure()
ax = Axes3D(fig)
x = np.random.randint(0, 100, 500)
print(x)
y = np.random.randint(1, 100, 500)
print(y)
z = np.random.randint(1, 100, 500)
print(z)
ax.scatter(x, y, z)
plt.show()
'''
'''
绘制3D曲线图
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(-6*np.pi, 1000)
#numpy.linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None)
#在start stop 范围内返回num的均匀分布样本
print(x)
y = np.sin(x)
z = np.cos(x)
fig = plt.figure()#创建一个画布
ax = Axes3D(fig)
ax.plot(x, y, z)
plt.show()
'''
'''
绘制3D曲面图
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np
#定义一个曲面方法
def fun(x, y):
return np.power(x, 2) + np.power(y, 2)
fig = plt.Figure()
ax = Axes3D(fig)
x = np.arange(-2, 2, 0.1)
y = np.arange(-2, 2, 0.1)
x, y = np.meshgrid(x, y)
z = fun(x, y)
ax.plot_surface(x, y, z)
plt.show()
'''
'''
绘制3D柱形图
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure()
ax = Axes3D(fig)
x = [1, 2]
for i in x:
y = [1, 2]
z = abs(np.random.randint(1, 10, 2))
ax.bar(y, z, i, zdir = 'g')
plt.show()
'''
上一篇: 逐帧动画