Skip to content

Add axes.aspect as an option to rcParams #15001

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
wants to merge 2 commits into from

Conversation

andrzejnovak
Copy link
Contributor

PR Summary

Add axes.aspect as an option to rcParams

PR Checklist

  • Has Pytest style unit tests
  • (Added) Code is Flake 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

@jklymak
Copy link
Member

jklymak commented Aug 7, 2019

Thanks for the PR but I’m against this as an rcParam. It will lead to lots of confusion particularly as we have some plotting methods that set the aspect ratio.

@ImportanceOfBeingErnest
Copy link
Member

ImportanceOfBeingErnest commented Aug 7, 2019

I don't think it is that confusing. Plotting methods take precedence over rcParams (One could also name it "default aspect" to make this more apparent.)

My problem with this is of a different nature. Since aspect is depending on the data to be plotted, how can you know the aspect prior to knowing what data to plot? Styles should be generally applicable, so I do wonder about a real world use case for this. I.e. when would you say "Oh, let's take the style that sets the aspect to 5."? Maybe there is such usecase, but I can't really think of one at the moment.

@jklymak
Copy link
Member

jklymak commented Aug 7, 2019

The confusion I was referring to was more that someone will forget they set this to equal and wonder why their axes was shrunk to zero height because their data aspect was 1:100000

@ImportanceOfBeingErnest
Copy link
Member

Well, sure, but that applies to almost any other parameter as well. You could also forget that you set the linewith to 0 and wonder why no data is shown etc.

@andrzejnovak
Copy link
Contributor Author

@jklymak Why is it confusing? Some methods will just overwrite it. The "problem" already exist for example for axes.grid

@ImportanceOfBeingErnest Here's my use case. I want to have a style with by default square plots. I also sometimes want a colorbar. Based on how I go about it, this will either shrink the main plot along x. Or make_axes_locatable() will shrink it proportionally. Either way I am left with a different size main plot than without the colorbar. This lets me set figsize slightly larger in x to fit the cbar without affecting the main plot.

image

Let me know if there would be a better way.

To be fair I don't think there's a use case for an aspect=5 😆

@ImportanceOfBeingErnest
Copy link
Member

In that usecase, if your data is not perfectly inside the [0,1] range, the axes shape would change, right? So it looks more like it would benefit from the box_aspect recently proposed in #14917.

@andrzejnovak
Copy link
Contributor Author

@ImportanceOfBeingErnest

In short, sometimes people just want to make a square plot.

Ha, perfect. Maybe add that as an option to rcParams then?

@ImportanceOfBeingErnest
Copy link
Member

One could think about that, yes. But one would need to be careful; currently this is a parameter set a posteriori by the user only. But if it's to be set at init time of any axes, it would sure cause problems e.g. with colorbar axes and also the interplay between the adjustable parameter would need to be sorted before the axes is drawn... so I'd say let's save this for a later time.

@andrzejnovak
Copy link
Contributor Author

Any suggestions what to do in the meantime to consistently produce plots with the same main axes size, with or without colorbar? My backup solution was to have some wrapper functions like https://matplotlib.org/3.1.1/gallery/axes_grid1/demo_axes_rgb.html

@ImportanceOfBeingErnest
Copy link
Member

Without having thought about it in depth... can you just always put a colorbar in and make it invisible in cases you don't need one?

@andrzejnovak
Copy link
Contributor Author

I mean that works, if I go for the fig, ax, = custom_wrapper() way, but it's still more complexity than what I was going for with this.

@jklymak
Copy link
Member

jklymak commented Aug 7, 2019

Yeah, but adding a rcParam, which has far-reaching implications, for a particular annoyance is not the way to go, in my opinion.

I'm not sure how you are laying out your plot, but constrained_layout should make all the subplots the same size. It will not resize the colorbar to match the parent if the parent shrinks due to aspect ratio. Thats a non-trivial problem for the way matplotlib is setup to handle layout. I'd suggest colorbars that don't take up the whole axes (using shrink=0.6 or some such). Or you can look at https://matplotlib.org/3.1.1/tutorials/toolkits/axes_grid.html and see if that works for your use case.

I'm going to close this, but if you want to open an issue with a runnable example of your code, we can try to help even if it turns into a feature request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Community support Users in need of help.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants