Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Redrawing canvas causes subplot positions to change when aspect='equal' used with rcParams['figure.autolayout'] = True #7648

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

Closed
ndeadly opened this issue Dec 20, 2016 · 6 comments
Labels
status: inactive Marked by the “Stale” Github Action

Comments

@ndeadly
Copy link

ndeadly commented Dec 20, 2016

As the title states, subplots with equal aspect ratio drift around within the figure when the canvas is redrawn with figure.autolayout set. The following code demonstrates the issue

import matplotlib.pyplot as plt
plt.rcParams['figure.autolayout'] = True

fig = plt.figure()
ax1 = fig.add_subplot(121, aspect='equal')
ax2 = fig.add_subplot(122, aspect='equal')
fig.canvas.mpl_connect('button_press_event', lambda event: event.canvas.draw())
fig.canvas.set_window_title('Click to redraw canvas')
plt.show()

The issue doesn't appear to occur with the default figure size, but if you resize the window horizontally the subplots drift around with each redraw until eventually settling on a position.

Platform: Windows 7
matplotlib: 1.5.3
python: 2.7.12

@tacaswell tacaswell modified the milestones: 2.0.1 (next bug fix release), 2.1 (next point release) Dec 20, 2016
@tacaswell
Copy link
Member

Interesting. There is obviously some coupled constraints here as the tight_layout code is trying to resize the axes to fill as much of the figure as possible and the equal aspect is trying to resize them so that the ratio between x/y is fixed in both data and screen space. We apply these constraints in sequence and they have now knowledge of each other.

Calling draw is apparently running a steps of an iterative optimization!

@efiring
Copy link
Member

efiring commented Dec 20, 2016

Yes, aspect-ratio handling and tight_layout are essentially hacks developed independently to solve two different problems in the absence of any integrated layout system, and in the context of the existing paradigm with most positioning being done in normalized coordinates.

@tacaswell tacaswell modified the milestones: 2.1 (next point release), 2.2 (next next feature release) Oct 3, 2017
@github-actions
Copy link

github-actions bot commented Apr 4, 2023

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!

@github-actions github-actions bot added the status: inactive Marked by the “Stale” Github Action label Apr 4, 2023
@jklymak
Copy link
Member

jklymak commented Apr 4, 2023

For simple systems layout='compressed' helps a lot with this issue. For more complex systems you probably need to do the layout by hand. I'd vote to close this.

@github-actions github-actions bot removed the status: inactive Marked by the “Stale” Github Action label Apr 5, 2023
Copy link

github-actions bot commented Apr 5, 2024

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!

@github-actions github-actions bot added the status: inactive Marked by the “Stale” Github Action label Apr 5, 2024
@tacaswell
Copy link
Member

I'm going to close this as no-action. This is an unintended, but mostly harmless, interaction between two systems that adjust the layout late in the draw cycle. For back-compatibility reasons we really can not make siginifacnt changes to either and as Jody notes, layout='constrained' works correctly in this case:

import matplotlib.pyplot as plt


fig = plt.figure(layout='constrained')
ax1 = fig.add_subplot(121, aspect='equal')
ax2 = fig.add_subplot(122, aspect='equal')
fig.canvas.mpl_connect('button_press_event', lambda event: event.canvas.draw())
# fig.canvas.set_window_title('Click to redraw canvas')
plt.show()

In summary:

  • the bug is mostly harmless
  • fixing it could be very disruptive
  • we have a new layout system that works better

@tacaswell tacaswell closed this as not planned Won't fix, can't repro, duplicate, stale Apr 5, 2024
@tacaswell tacaswell removed this from the future releases milestone Apr 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: inactive Marked by the “Stale” Github Action
Projects
None yet
Development

No branches or pull requests

4 participants