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?
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.
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')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With