Skip to content

Setting aspect ratio for semi-log plots #8878

Closed

Description

@chrisgoedde

Is there a technical reason you can't set the aspect ratio of semi-log plots? Doing so yields the following:

UserWarning: aspect is not supported for Axes with xscale=log, yscale=linear

This would be very useful, and seems like a hole in the current implementation.

Activity

  1. geib7592 commented on Jul 14, 2017

    @geib7592

    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?

  2. chrisgoedde commented on Jul 14, 2017

    @chrisgoedde
    Author

    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?

  3. added this to the milestone on Jul 14, 2017
  4. tacaswell commented on Jul 14, 2017

    @tacaswell
    Member

    Do you want to set x / log(y) == Const or y / 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.

  5. geib7592 commented on Jul 14, 2017

    @geib7592

    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.

  6. chrisgoedde commented on Jul 17, 2017

    @chrisgoedde
    Author

    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.

  7. poplarShift commented on May 23, 2019

    @poplarShift

    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.

    @tacaswell any opinion on this?

  8. timhoffm commented on May 31, 2019

    @timhoffm
    Member

    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.

  9. chrisgoedde commented on May 31, 2019

    @chrisgoedde
    Author

    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.

  10. QuLogic commented on Jul 18, 2019

    @QuLogic
    Member

    Closed by #14727.

  11. modified the milestones: needs sorting, v3.2.0 on Jul 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions