Add `axes.aspect` as an option to rcParams by andrzejnovak · Pull Request #15001 · matplotlib/matplotlib · GitHub
Skip to content

Add axes.aspect as an option to rcParams - #15001

Closed
andrzejnovak wants to merge 2 commits into
matplotlib:masterfrom
andrzejnovak:AddrcParam
Closed

andrzejnovak wants to merge 2 commits into
matplotlib:masterfrom
andrzejnovak:AddrcParam

Conversation

@andrzejnovak

Copy link
Copy Markdown
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

jklymak commented Aug 7, 2019

Copy link
Copy Markdown
Member

@ImportanceOfBeingErnest

ImportanceOfBeingErnest commented Aug 7, 2019

Copy link
Copy Markdown
Member

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

jklymak commented Aug 7, 2019

Copy link
Copy Markdown
Member

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

jklymak commented Aug 7, 2019

Copy link
Copy Markdown
Member

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