问题描述
因此,我正在尝试创建一个图形,该图形显示数据点的3d图以及其他3个子图中的3个投影.我可以毫无问题地为投影添加子图,但是当我尝试将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.
这是我的代码:
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'
which throws back: 'AxesSubplot' object has no attribute 'transFigure'
我正在使用matplotlib 0.99.3,非常感谢您的帮助!
I'm using matplotlib 0.99.3, any help would be greatly appreciated, thanks!
推荐答案
我一直在寻找一种使用漂亮的fig, axes = plt.subplots(...)
快捷方式创建3D图的方法,但是由于我只是浏览了 Matplotlib的mplot3d教程,我想分享这个网站顶部的报价.
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.
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
注意
在1.0.0版之前,创建3D轴的方法不同.对于使用较旧版本的matplotlib的用户,将ax = fig.add_subplot(111,projection ='3d')更改为ax = Axes3D(fig).
Note
Prior to version 1.0.0, the method of creating a 3D axes was different. For those using older versions of matplotlib, change ax = fig.add_subplot(111, projection='3d') to ax = Axes3D(fig).
因此,如果必须使用&p; 1.0.0版的Matplotlib,则应将其考虑在内.
So if you have to use the <1.0.0 version of Matplotlib, this should be taken into account.
这篇关于尝试将3d子图添加到matplotlib图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!