Skip to content

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

Open

Description

@JanAlster

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:

Activity

  1. oscargus commented on Aug 8, 2022

    @oscargus
    Member

    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.

  2. oscargus commented on Oct 21, 2022

    @oscargus
    Member

    Probably related to #19519

  3. github-actions commented on Jan 2, 2026

    @github-actions

    This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!

  4. rcomer commented on Oct 16, 2026

    @rcomer
    Member

    I can still reproduce this with current main.

  5. added
    keepItems to be ignored by the “Stale” Github Action
    and removed
    status: inactiveMarked by the “Stale” Github Action
    on Oct 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions