繁体   English   中英

在 Python 中绘制 3D 图

[英]Plotting a 3D graph in Python

我有 3 个形状为 (1000,1) 的向量“x1”、“x2”和“目标”,我想在 3D 图上对此进行 plot。

使用代码时

targets = targets.reshape(observations,)
fig = plt.figure()
ax = fig.add_subplot(111, projection = '3d')
ax.plot(x1,x2,targets)
ax.set_xlabel("x1")
ax.set_ylabel("x2")
ax.set_zlabel("targets")
ax.view_init(azim=200)
plt.show()

我收到错误消息:操作数无法与重新映射的形状 [original->remapped]: (1000,) 和请求的形状 (1000,1) 一起广播

如果我删除代码targets = targets.reshape(observations,)以将形状重新映射为 (1000,1),则会出现错误: Line3D' object has no attribute '_verts3d'

据我了解, plot 需要 3 个向量,每个向量具有一维。 如果您只是从 arrays 中提取一列数据,我认为您没问题。 请参见下面的示例:

import numpy as np
import matplotlib.pyplot as plt

x1 = np.random.random((1000,1))
x2 = np.random.random((1000,1))
targets = np.random.random((1000,1))

x1 = x1[:,0]
x2 = x2[:,0]
targets = targets[:,0]

# targets = targets.reshape(targets,)
fig = plt.figure()
ax = fig.add_subplot(111, projection = '3d')
ax.plot(x1,x2,targets)
ax.set_xlabel("x1")
ax.set_ylabel("x2")
ax.set_zlabel("targets")
ax.view_init(azim=200)
plt.show()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM