三维散点图
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import cm
from mpl_toolkits.mplot3d import Axes3D
# 二元二次函数图像
fig = plt.figure()
ax = Axes3D(fig)
fig.add_axes(ax)
x = np.arange(-5, 5, 0.3)
y = np.arange(-5, 5, 0.3)
X, Y = np.meshgrid(x, y) # 网格的创建,生成二维数组,这个是关键
Z = X*X + Y*Y + X
plt.xlabel('x')
plt.ylabel('y')
# 将函数显示为3d,rstride和cstride代表row(行)和column(列)的跨度cmap为色图分类
ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap='rainbow')
# 标点
for i in range(0,10):
# 使用np.random随机x和y的坐标,然后得到z州的坐标
x = np.random.uniform(-3.5,3)
y = np.random.uniform(-3,3)
ax.scatter(x,y,x*x+y*y+x,color='red',marker='x')
# ax.scatter3D(X,Y,Z)
plt.show()
三维曲线图
import matplotlib as mpl
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
import matplotlib.pyplot as plt
# 设置图例字号
mpl.rcParams['legend.fontsize'] = 10
# 方式2:设置三维图形模式
fig = plt.figure()
ax = fig.gca(projection='3d')
# 测试数据
theta = np.linspace(-4 * np.pi, 4 * np.pi, 100)
z = np.linspace(-4, 4, 100) / 4
r = z**3 + 1
x = r * np.sin(theta)
y = r * np.cos(theta)
# 绘制图形
ax.plot(x, y, z, label='parametric curve')
# 显示图例
ax.legend()
# 显示图形
plt.show()
标签:plt,python,mpl,--,散点,fig,ax,np,import From: https://www.cnblogs.com/hyy-0/p/17397871.html