This question is related to Set size of matplotlib figure with 3d subplots.
Here is an exmple code.
fig = plt.figure()
fig.set_size_inches(10, 4)
ax = fig.gca(projection='3d')
The code above is the one I used for creating 3D plots in 2019.
Since matplotlib 3.4, calling gca() with keyword arguments was deprecated.
Moreover, the 3D axis does not fit into the figure size anymore.
Here is an example for matplotlib 3.4.3.
fig = plt.figure()
fig.set_size_inches(10, 4)
ax = plt.subplot(1, 1, 1)
fig = plt.figure()
fig.set_size_inches(10, 4)
ax = plt.subplot(1, 1, 1, projection='3d')
Although the old version of matplotlib automatically fit the 3D axis into the figure (I'm sorry but I didn't save the exact version number), the current-3.4.3 version of the matplotlib does not fit the 3D axis into the figure size anymore.
I know I can use Axes3D.set_box_aspect()
as suggested in set matplotlib 3d plot aspect ratio?. However, it is hard to find the exact aspect values to make the axis fit into the figure size. autoscale()
also does not help in this case.
In summary, the question is: is there any method to (1) automatically fit the 3D axis into the figure (or, change the size of a 3D axis) (2) and prevent marginal spaces?