尝试将 3d 子图添加到 matplotlib 图形中
因此,我尝试创建一个图形,该图形呈现数据点的 3D 图,以及其他 3 个子图中的 3 个投影。我可以毫无问题地添加投影的子图,但是当我尝试将 3 维图放入图形中时,事情会适得其反。
这是我的代码:
def plotAll(data):
fig = plt.figure()
plot_3d = fig.add_subplot(221)
ax = Axes3D(plot_3d)
for i,traj in enumerate(data.values()):
ax.plot3D([traj[0][-1]],[traj[1][-1]],[traj[2][-1]],".",color=[0.91,0.39,0.046])
#plot_12v13 = fig.add_subplot(222)
#plot_projections(data,0,1)
#plot_13v14 = fig.add_subplot(223)
#plot_projections(data,1,2)
#plot_12v14 = fig.add_subplot(224)
#plot_projections(data,0,2)
#plt.plot()
它返回: 'AxesSubplot' 对象没有属性 'transFigure'
我正在使用 matplotlib 0.99.3,任何帮助将不胜感激,谢谢!
So I'm trying to create a figure that presents a 3d plot from data points, along with the plots 3 projections in 3 other subplots. I can add the subplots for the projections with no problems, but when I try to place the 3 dimensional plot into the figure things backfire.
here's my code:
def plotAll(data):
fig = plt.figure()
plot_3d = fig.add_subplot(221)
ax = Axes3D(plot_3d)
for i,traj in enumerate(data.values()):
ax.plot3D([traj[0][-1]],[traj[1][-1]],[traj[2][-1]],".",color=[0.91,0.39,0.046])
#plot_12v13 = fig.add_subplot(222)
#plot_projections(data,0,1)
#plot_13v14 = fig.add_subplot(223)
#plot_projections(data,1,2)
#plot_12v14 = fig.add_subplot(224)
#plot_projections(data,0,2)
#plt.plot()
which throws back:
'AxesSubplot' object has no attribute 'transFigure'
I'm using matplotlib 0.99.3, any help would be greatly appreciated, thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您想使用
plt.subplots
而不是plt.subplot
(请参阅差异 这里),那么你可以做这样的事情:嗯,我不知道如何使用
plt.subplots
将各个轴设置为3D。如果有人可以发表评论,那将会很有帮助。If you would like to use
plt.subplots
instead ofplt.subplot
(see the difference here), then you can do something like this one:Well, I don't know how to set individual axes as 3D using
plt.subplots
. It would be helpful if someone could comment down.我正在寻找一种使用漂亮的
fig,axes = plt.subplots(...)
快捷方式创建 3D 绘图的方法,但由于我刚刚浏览了 Matplotlib 的 mplot3d 教程,我想分享本网站顶部的一句话。因此,如果您必须使用 <1.0.0 版本的 Matplotlib,则应考虑到这一点。
I was searching for a way to create my 3D-plots with the nice
fig, axes = plt.subplots(...)
shortcut, but since I just browsed Matplotlib's mplot3d tutorial, I want to share a quote from the top of this site.So if you have to use the <1.0.0 version of Matplotlib, this should be taken into account.
创建 3D 轴的首选方法是提供
projection
关键字:不幸的是,您没有提供包含合适数据的工作示例,因此我无法测试代码。另外,我建议更新到较新版本的 matplotlib。
The preferred way of creating an 3D axis is giving the
projection
keyword:Unfortunately, you didn't supply a working example with suitable data, so I couldn't test the code. Also, I would recommend updating to a newer version of matplotlib.