Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

Is there anyway I can turn an existing ax object into a 3d ax?

like image 456
Demetri Pananos Avatar asked Feb 04 '16 19:02

Demetri Pananos


People also ask

How do you plot 3 axis in Python?

Using subplots() method, create a figure and a set of subplots. Plot [1, 2, 3, 4, 5] data points on the left Y-axis scales. Using twinx() method, create a twin of Axes with a shared X-axis but independent Y-axis, ax2. Plot [11, 12, 31, 41, 15] data points on the right Y-axis scale, with blue color.


1 Answers

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')
like image 143
tmdavison Avatar answered Dec 05 '22 00:12

tmdavison