Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add location keyword argument to Colorbar #23267

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

Merged
merged 1 commit into from
Nov 7, 2022

Conversation

oscargus
Copy link
Member

@oscargus oscargus commented Jun 14, 2022

PR Summary

Closes #22676

Is this an API change or a user change?

Will add an unrelated test for #23260 here as well. Added. However, they do not look great... The png looks OK, but locally I get in Spyder:
image
so there it seems like there is a bit of overlap that is not visible in the test image. For the svg there is a gap instead, although this seems to depend on the renderer...

Also, I do not understand why the test images are not just four squares as the pasted image...

PR Checklist

Tests and Styling

  • Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (install flake8-docstrings and run flake8 --docstring-convention=all).

Documentation

  • New features are documented, with examples if plot related.
  • New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • [N/A] API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).
  • Documentation is sphinx and numpydoc compliant (the docs should build without error).

@oscargus
Copy link
Member Author

I also realized that there is a change here that may not really be wanted (or it may be). Earlier, passing e.g. orientation='horizontal' always gave ticklocation 'bottom'. Now, if passing orientation='horizontal' and a valid location, the ticklocation depends on if the location is 'top' or 'bottom'. Which makes sense and is consistent with what location does for make_axis and make_axis_gridspec.

@oscargus oscargus force-pushed the colorbarlocation branch 2 times, most recently from bdb43a3 to f44b0b4 Compare June 18, 2022 09:01
@oscargus oscargus marked this pull request as ready for review June 18, 2022 09:05
@story645
Copy link
Member

story645 commented Jun 19, 2022

This is awesome and I'm fairly sure should get a new feature/what's new write up.

Copy link
Member

@jklymak jklymak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree with the need for a what's-new.


The ``colorbar`` method now supports a ``location`` keyword argument
to more easily position the color bar. This is useful when providing
your own inset axes using the ``cax`` keyword argument and behaves
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this sounds like this kwarg only works with a passed in cax & if that's not the case than please also add an example for the not-cax case

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The earlier version is documented, but is not used by colorbar (passed to either make_axes or make_axes_gridspec. I agree, however, that the current formulation is not ideal. Will try to modify it (now that I reminded myself of the differences).

Copy link
Member

@timhoffm timhoffm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've not yet followed the details here, but I would have expected that this can build on top of _normalize_location_orientation. Am I wrong there?

@oscargus
Copy link
Member Author

oscargus commented Jun 22, 2022

_normalize_location_orientation also sets anchor, panchor and pad. I wasn't sure that one wanted those to be modified here? Also, here we need to keep the original value of location to keep track of if location and orientation was passed.

So while it could be used, it couldn't just be used to update the kwargs and it would do some additional stuff as well, which seemed redundant to me (but now there is redundant code instead...).

@oscargus
Copy link
Member Author

I'll think it through more carefully, but the rationale at the time was this.

@timhoffm
Copy link
Member

So while it could be used, it couldn't just be used to update the kwargs and it would do some additional stuff as well, which seemed redundant to me (but now there is redundant code instead...).

I'll think it through more carefully, but the rationale at the time was this.

You could also introduce a lower-level function that is used here and inside of _normalize_location_orientation to avoid duplication - if that helps.

@oscargus oscargus marked this pull request as draft July 7, 2022 07:18
@oscargus
Copy link
Member Author

Got around to this and at least now it is checked and set in a single location.

@oscargus oscargus force-pushed the colorbarlocation branch 2 times, most recently from 08c2062 to 0442dd3 Compare August 18, 2022 19:52
@oscargus oscargus added this to the v3.6.0 milestone Aug 18, 2022
@oscargus oscargus marked this pull request as ready for review August 18, 2022 19:56
@tacaswell tacaswell modified the milestones: v3.6.0, v3.7.0 Aug 19, 2022
@oscargus oscargus force-pushed the colorbarlocation branch 3 times, most recently from 0515d39 to ee796c5 Compare November 2, 2022 13:31
@oscargus
Copy link
Member Author

oscargus commented Nov 2, 2022

Finally got back to this. The unrelated test is dropped.

Copy link
Member

@jklymak jklymak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a small documentation concern


ticklocation : {'auto', 'left', 'right', 'top', 'bottom'}

drawedges : bool

filled : bool

location : None or {'left', 'right', 'top', 'bottom'}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this needs some description about how it interacts with orientation and ticklocation?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added a bit of text (copied from the top) and updated the docs for ticklocation. There should maybe be another way to describe how all these are related if only some are given.

@QuLogic QuLogic modified the milestones: v3.7.0, v3.6.3 Nov 3, 2022
@jklymak jklymak merged commit f975291 into matplotlib:main Nov 7, 2022
@jklymak
Copy link
Member

jklymak commented Nov 7, 2022

Thanks @oscargus - definitely useful addition!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[ENH]: Colorbar should support location kwarg that sets both orientation and ticklocation
7 participants