You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Just to clarify. You want to be able to set a factor of 10 along the x axis to be the same (for aspect=1) distance on the page as one (linear) unit along the y axis?
What I'm really trying to do is set the actual aspect ratio of the axes (measured in inches, cm, pixels, or whatever) to a certain value, using the method described in these answers. Works fine with lin-lin or log-log plots, but fails for semi-log plots because set_aspect doesn't work for semi-log plots.
It seems like you want something slightly different. set_aspect sets the ratio of how data units relate to page units for the two axes. This indirectly changes the aspect ratio of the axes themselves (total height/ total width). But it seems you want to directly set the total aspect ratio of the axes themselves, regardless of how data are squished in x or y.
The best way to set that aspect ratio probably depends on what exactly you're doing. Usually I use plt.subplots and set figsize to what I need in the end, and I use subplots_adjust to get the axes exactly where I want them. But if you're using add_axes to add your axes, then you can set their width and height then when you call add_axes. You might also look into ax.get_position() and ax.set_position.
Thanks, I'll try that instead. Just as a note, the documentation is very unclear about this. For example, under Axes.set_aspect the documentation says, for adjustable = 'box', "change physical size of axes", which would seem to imply that set_aspect(ratio, adjustable = 'box') should change the physical size of the axes to match ratio, which seems not to be true.
I would understand @geib7592 's point that the aspect is about the ratio of the underlying units if it was only supported for linear axes in the first place. However, it is already supported for loglog axes by fixing the ratio log(y)/log(x), so why not just add semilog axes too by fixing log(y)/x? I'd be happy to make a PR. Manually adjusting subplot aspect ratios in figure coordinates is a bit tiresome, especially when you haven't settled on the number of panels or overall size yet.
Just to be sure that I understand this correctly: An aspect ratio of 1 for log(y)/x would mean a y-decade would be of the same size as a step of 1 (or alternatively 10) in x? There's no real concept of 'equal' on a semi-log scale, so as opposed to linear and loglog, the definition of aspect=1 is rather arbitrary. But I don't see why we shouldn't support this.
Activity
geib7592 commentedon Jul 14, 2017
Just to clarify. You want to be able to set a factor of 10 along the x axis to be the same (for aspect=1) distance on the page as one (linear) unit along the y axis?
chrisgoedde commentedon Jul 14, 2017
Yes, I think so.
What I'm really trying to do is set the actual aspect ratio of the axes (measured in inches, cm, pixels, or whatever) to a certain value, using the method described in these answers. Works fine with lin-lin or log-log plots, but fails for semi-log plots because set_aspect doesn't work for semi-log plots.
But maybe there's a better way to achieve this?
tacaswell commentedon Jul 14, 2017
Do you want to set
x / log(y) == Constory / y == Const?If you just want to make the axes fixed, I think you just need set the figure size and a axes position in a coordinated way.
geib7592 commentedon Jul 14, 2017
It seems like you want something slightly different.
set_aspectsets the ratio of how data units relate to page units for the two axes. This indirectly changes the aspect ratio of the axes themselves (total height/ total width). But it seems you want to directly set the total aspect ratio of the axes themselves, regardless of how data are squished in x or y.The best way to set that aspect ratio probably depends on what exactly you're doing. Usually I use
plt.subplotsand setfigsizeto what I need in the end, and I usesubplots_adjustto get the axes exactly where I want them. But if you're usingadd_axesto add your axes, then you can set their width and height then when you calladd_axes. You might also look intoax.get_position()andax.set_position.chrisgoedde commentedon Jul 17, 2017
Thanks, I'll try that instead. Just as a note, the documentation is very unclear about this. For example, under Axes.set_aspect the documentation says, for adjustable = 'box', "change physical size of axes", which would seem to imply that set_aspect(ratio, adjustable = 'box') should change the physical size of the axes to match ratio, which seems not to be true.
poplarShift commentedon May 23, 2019
I would understand @geib7592 's point that the aspect is about the ratio of the underlying units if it was only supported for linear axes in the first place. However, it is already supported for loglog axes by fixing the ratio
log(y)/log(x), so why not just add semilog axes too by fixinglog(y)/x? I'd be happy to make a PR. Manually adjusting subplot aspect ratios in figure coordinates is a bit tiresome, especially when you haven't settled on the number of panels or overall size yet.@tacaswell any opinion on this?
timhoffm commentedon May 31, 2019
Just to be sure that I understand this correctly: An aspect ratio of 1 for
log(y)/xwould mean a y-decade would be of the same size as a step of 1 (or alternatively 10) in x? There's no real concept of 'equal' on a semi-log scale, so as opposed to linear and loglog, the definition of aspect=1 is rather arbitrary. But I don't see why we shouldn't support this.chrisgoedde commentedon May 31, 2019
Yes, that was the idea. I agree equating a decade to a step of 1 is somewhat arbitrary, but it seems pretty natural to me since log(10) = 1.
QuLogic commentedon Jul 18, 2019
Closed by #14727.