Can I turn an existing ax object into a 3d projection?

后端 未结 1 1095
心在旅途
心在旅途 2021-01-07 05:53

I\'ve created some axes using plt.subplots(nrows = 2, ncols = 2). I would like to make ax[1,1] a 3d axis so I can make a plot like this.

I

相关标签:
1条回答
  • 2021-01-07 06:08

    No, because a 3D axis is a matplotlib.axes._subplots.Axes3DSubplot object, while a regular axis is a matplotlib.axes._subplots.AxesSubplot object.

    So, its not just the case of changing one property of an existing object, since its a completely different object that gets created when you add_subplot(projection='3d').

    I think you would have to explicitly create your subplots, something like:

    fig=plt.figure()
    ax1=fig.add_subplot(2,2,1)
    ax2=fig.add_subplot(2,2,2)
    ax3=fig.add_subplot(2,2,3)
    ax4=fig.add_subplot(2,2,4,projection='3d')
    

    Or, alternatively, remove the 2D axis and add it back in as a 3D axis:

    fig,ax = plt.subplots(nrows = 2, ncols = 2)
    ax[1,1].remove()
    ax[1,1]=fig.add_subplot(2,2,4,projection='3d')
    
    0 讨论(0)
提交回复
热议问题