Skip to content

Repositioned Axes3d do not scale size with Figure size change #20655

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
JanAlster opened this issue Jul 16, 2021 · 2 comments
Open

Repositioned Axes3d do not scale size with Figure size change #20655

JanAlster opened this issue Jul 16, 2021 · 2 comments

Comments

@JanAlster
Copy link

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):
test_original_size
Figure enlarged after axes are created and shifted:
test_large_size

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:
test_big_figure

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:
@oscargus
Copy link
Member

oscargus commented Aug 8, 2022

I can confirm this. However, it doesn't hold for the interactive backends, only the ones generating files (both jpg/png and pdf).

To further narrow it down, it seems related to subplots. Using a single axis and reposition it, the size it not identical.

@oscargus
Copy link
Member

Probably related to #19519

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants