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

Skip to content

aspect='equal' ignored when parasitic axis added with twinx/twiny #7654

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 21, 2016 · 4 comments
Closed

aspect='equal' ignored when parasitic axis added with twinx/twiny #7654

ndeadly opened this issue Dec 21, 2016 · 4 comments
Assignees
Labels
Difficulty: Medium https://matplotlib.org/devdocs/devel/contribute.html#good-first-issues status: closed as inactive Issues closed by the "Stale" Github Action. Please comment on any you think should still be open. status: inactive Marked by the “Stale” Github Action

Comments

@ndeadly
Copy link

ndeadly commented Dec 21, 2016

Consider an axis with equal aspect ratio

from matplotlib import pyplot as plt

fig = plt.figure()
ax1 = fig.add_subplot(111, aspect='equal')
ax1.grid()
plt.show()

figure_1-5


Adding a parasitic axis with twinx() causes the plot to completely ignore aspect='equal'

from matplotlib import pyplot as plt

fig = plt.figure()
ax1 = fig.add_subplot(111, aspect='equal')
ax1.grid()
ax2 = ax1.twinx()
plt.show()

figure_1-6


Creating the primary axis with the keyword argument adjustable='box-forced' causes it to obey aspect='equal' but the parasitic axis does not.

from matplotlib import pyplot as plt

fig = plt.figure()
ax1 = fig.add_subplot(111, adjustable='box-forced', aspect='equal')
ax1.grid()
ax2 = ax1.twinx()
plt.show()

figure_1-7


Interestingly, everything works if the primary axis is created with host_subplot (note adjustable='box-forced' is still required). However, it seems to be prone to a similar issue to #7648 if figure.autolayout is set

import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1 import host_subplot

fig = plt.figure()
ax1 = host_subplot(111, adjustable='box-forced', aspect='equal')
ax1.grid()
ax2 = ax1.twinx()
plt.show()

figure_1-8

Platform: Windows 7
matplotlib: 1.5.3
python: 2.7.12

@tacaswell tacaswell added this to the 2.0.1 (next bug fix release) milestone Dec 21, 2016
@tacaswell tacaswell added the Difficulty: Medium https://matplotlib.org/devdocs/devel/contribute.html#good-first-issues label Dec 21, 2016
@efiring
Copy link
Member

efiring commented Dec 21, 2016

Two comments related to this:

  1. 'box-forced' is inherently designed to break things. I have always maintained it was a bad idea. The best that can be said for it is that inclusion of the word 'forced' should warn the user to expect breakage. Some things will work, others won't. You are dealing with an over-determined system, so things will work only if all constraints turn out to be consistent.
  2. Your statement that "Adding a parasitic axis with twinx() causes the plot to completely ignore aspect='equal'" is not correct. The original axis still has a data aspect ratio of 1, which it is achieving by adjusting the data limits. twinx turns on axis sharing, which incompatible with aspect ratio control unless the adjustable is 'datalim'.

We used to have a warning when the adjustable parameter was switched from 'box' to 'datalim' in this case. It is presently commented out. I think we need to uncomment it, and maybe even give it a longer explanation.

@QuLogic QuLogic modified the milestones: 2.0.1 (next bug fix release), 2.0.2 (next bug fix release) May 3, 2017
@tacaswell tacaswell modified the milestones: 2.1.1 (next bug fix release), 2.2 (next feature release) Oct 9, 2017
@efiring
Copy link
Member

efiring commented Jan 26, 2018

This is partly addressed by #10033, but it looks like more can be done. Instead of setting adjustable to 'datalim' on twinned axes, I think that it would be possible to check at drawing time whether the aspect ratio is specified for more than a single axes in a twinned pair, and switch to datalim only in that case. A 'box' adjustable should work for twinned axes with only one aspect ratio specified; or perhaps also if specified aspect ratios are identical.

@efiring efiring self-assigned this Jan 26, 2018
@Dhrumil0
Copy link

I was investigating a fix for this bug and even after the partial changes made by 10033 there still seem to be issues and I need clarification on how it's supposed to behave.

  1. What should the adjustable be when an axes and its twin both have aspect set to 'auto'?

  2. What if the aspects for both axes are the same? Should the adjustable be 'box' in these cases?

  3. What should happen in cases where the aspects are different like 'auto' and 'equal'? I tried to set this to datalim in the drawing time but I noticed that the current bug still persists with one of the axis going to 0.8 and the other one going to 1.0. Is this expected?

@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
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale May 5, 2023
@rcomer rcomer added the status: closed as inactive Issues closed by the "Stale" Github Action. Please comment on any you think should still be open. label May 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Difficulty: Medium https://matplotlib.org/devdocs/devel/contribute.html#good-first-issues status: closed as inactive Issues closed by the "Stale" Github Action. Please comment on any you think should still be open. status: inactive Marked by the “Stale” Github Action
Projects
None yet
Development

No branches or pull requests

6 participants