from matplotlib import pyplot as plt
fig = plt.figure()
ax1 = fig.add_subplot(111, aspect='equal')
ax1.grid()
plt.show()
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()
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()
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
'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.
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.
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.
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.
What should the adjustable be when an axes and its twin both have aspect set to 'auto'?
What if the aspects for both axes are the same? Should the adjustable be 'box' in these cases?
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?
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!
Activity
efiring commented on Dec 21, 2016
Two comments related to this:
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.
efiring commented on 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.
Dhrumil0 commented on Mar 14, 2018
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.
What should the adjustable be when an axes and its twin both have aspect set to 'auto'?
What if the aspects for both axes are the same? Should the adjustable be 'box' in these cases?
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 commented on 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!