Trying to add a 3d subplot to a matplotlib figure

对着背影说爱祢 提交于 2019-12-01 06:26:14

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.

New in version 1.0.0: This approach is the preferred method of creating a 3D axes.

import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

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).

So if you have to use the <1.0.0 version of Matplotlib, this should be taken into account.

The preferred way of creating an 3D axis is giving the projection keyword:

def plotAll(data):
    fig = plt.figure()
    ax = fig.add_subplot(221, projection='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()

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!