-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
set_ylim not working with plt.axis('equal') #8093
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
Comments
Sorry I forgot to mention I am using matplotlib 2.0.0 and the last command has no effect in my case. |
Hmm, this is working fine for me on 2.0.0 using python 3.6, in a fresh conda environment. What version of python are you using and what OS are you running? |
Are you in interactive mode? Might be a refresh bug.
…On Fri, Feb 17, 2017 at 8:58 AM, David Stansby ***@***.***> wrote:
Hmm, this is working fine for me on 2.0.0 using python 3.6, in a fresh
conda environment. What version of python are you using and what OS are you
running?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#8093 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AARy-Jkeml_KFqWjIhr02lnlnxmUqRJCks5rdad7gaJpZM4MEHDL>
.
|
Sorry I didn't provide this information. I see it with Python 2.7.13 using IPython 5.1.0. However, my example was not well chosen. The actual problem appears in this example (also when using plt.savefig without IPython):
However, maybe this is in fact not a bug but a feature, since this behavior guaranties a fixed aspect ratio of plots, which could be handy when generating multiple plots. I was just surprised that the axes can be longer than the given limits. But it can be a good thing that matplotlib sees them as lower limits with respect to the other axis. Maybe the current behavior is not a bad idea and no changes are actually required. |
Yep, I can confirm that example doesn't seem to be working. |
You need to call |
@fkbreitl Just to check, you edited the orginal post? I can not see a difference between the two examples... I think the fundamental problem is that with a fixed aspect ratio the system is over constrained so we drop one of the constraints. The logic for all of this lives in |
@tacaswell The difference is that the first example respects the limits and the second doesn't. If you say |
But I don't see how the examples are different, they are both plt.plot((.1, .3))
plt.axis('equal')
plt.gca().set_ylim(.1, .2) I suggest having a look at the source. |
@tacaswell Oh, you are right. It seems like dstansby edited my example.
|
I found this page searching for a solution to the same problem. Here is a code snippet:
The x-axis was correct, but the y-axis autoscaled. Interestingly, if I tried to manually scale the y=axis (using the check mark on the displayed plot) the values would not be accepted when I pushed apply. Python 3.5.2, Matplotlib 1.5.3 |
@beuse You want |
@tacaswell Yes you thought correctly. Thanks. |
try using plt.gca().set_aspect('equal') |
@tacaswell Thank you a billion!!!! That's exactly what I was looking for! All the other answers don't work! |
@aggna I can't follow your example. Please boil it down to a minimal example if this is still a problem for you. Please also note that after |
@timhoffm @tacaswell hopefully this one is more demonstrative of the problem. Case 1If I don't have two subplots, Case 2The automated code fails to work when you have two subplots. For some reason, it fixes a figure size (even if you don't give it one) and Case 3Manually chosing the figure size and subplot sizes first, depending on the data that is being plotted. Case 4Manually chosing the figure size and subplot sizes first, depending on the data that is being plotted. Then use Attaching code. Set up - no plotting yet
Case 1 code
Case 2/3/4 code
|
@aggna This is correct and documented behavior.
|
Printing a figure w/ |
I think I understand the issue. Minimal example:
The problem: The lines are cut off. Now unlike other similar issues, which arise because the system is overconstrained, this is not the case here. The only constraints here are the equal aspect for both axes, and the sharing between the x axes. This would in principle still allow to adjust the x axis limits, such that the whole line is shown. So the expected outcome would be this: |
Yeah theoretically. But you’d need a constraint solver to figure it out. I’d say expecting sharing,autoscaling, and maintaining aspect across a number of axes is a pretty hard problem and you can either set up a big machinery to solve it or the user need not rely on autoscaling. |
@ImportanceOfBeingErnest Yes, that's what I was thinking |
@jklymak The constraints aren't that complicated to solve, IMO. Just a bit of subtraction and division, as you can see from my O[10] lines of code in the second block in setup. All plotting algorithms probably have the code structure that takes data range and uses those to implement the default axes limit. So now all they gotta do is take the grid-spec and figsize into account to decide the new axes limits. |
Sounds easy! |
@timhoffm Did you mean For folks who might encounter this problem later at some point, here's what you get if you replace |
Let's not confuse things here. The figure size is fixed (bbox_inches="tight" does not change the figure size, it just renders on a larger/smaller pixel space). Anything that would change the figure size is on a totally different level. The issue isolated above is about the datalimits. Possibly this is hard, too, but I still need to convince myself of that. |
It renders a different figure size in inches, but if you mean it doesn't change the figure size parameter for calculation of the axes positions, I agree with that. (I wouldn't think in pixels, since that does often change on a savefig, and is irrelevant for many of the backends). |
This worked for me. I had the same issue as OP. |
Uh oh!
There was an error while loading. Please reload this page.
set_ylim
has no effect when using plt.axis('equal'):The text was updated successfully, but these errors were encountered: