Open
Description
Bug report
Bug summary
If Axes3d was repositioned by set_position() prior to figure size change, it will not adjust its size. Normal axes behave differently.
Code for reproduction
import matplotlib.pyplot as pl
def adjustPos(ax, shift=-0.08):
pos = ax.get_position()
ax.set_position(pos.translated(shift, 0))
#axes grid
N = 10
C = 2
fig = pl.figure() #default (small) size
fig2 = pl.figure()
fig2.set_size_inches(7,2*N)
def adjustPos(ax, shift=-0.08):
pos = ax.get_position()
ax.set_position(pos.translated(shift, 0))
for ii in range(N):
#add and shift (by zero) normal and 3d axes
ax = fig.add_subplot(N, C, 1+ii*C)
adjustPos(ax, 0)
ax = fig.add_subplot(N, C, 1+ii*C+1, projection="3d")
adjustPos(ax, 0)
#the same for already large fig2
ax = fig2.add_subplot(N, C, 1+ii*C)
adjustPos(ax, 0)
ax = fig2.add_subplot(N, C, 1+ii*C+1, projection="3d")
adjustPos(ax, 0)
fig.savefig("test_original_size.jpg", dpi=300)
fig.set_size_inches(7,2*N)
fig.savefig("test_large_size.jpg", dpi=300)
fig2.savefig("test_big_figure.jpg", dpi=300)
Actual outcome
If axes positions are adjusted by calling set_position(), even if the actual shift is 0, Axes3D will keep its size determined for the original size of figure.
Original figure size (axes do not fit comfortably):
Figure enlarged after axes are created and shifted:
This effect will not take place if set_position() is not called. The issue can be easily avoided by setting figure size ahead of axes creation as done with fig2:
However, I would expect this behaviour regardless of where the figure size is changed.
Matplotlib version
- Operating system: Debian GNU/Linux 10
- Matplotlib version (
import matplotlib; print(matplotlib.__version__)
): 3.4.2 - Matplotlib backend (
print(matplotlib.get_backend())
): Qt5Agg - Python version: Python 3.7.3
- Other libraries: