Skip to content
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

Configurable colorbar in iris.quickplot #5970

Closed
trexfeathers opened this issue May 22, 2024 · 9 comments · Fixed by #6169
Closed

Configurable colorbar in iris.quickplot #5970

trexfeathers opened this issue May 22, 2024 · 9 comments · Fixed by #6169
Assignees
Labels
Good First Issue A good issue to take on if you're just getting started with Iris development
Milestone

Comments

@trexfeathers
Copy link
Contributor

trexfeathers commented May 22, 2024

✨ Feature Request

I would like to be able to configure colorbar creation via kwargs in iris.quickplot functions.

Motivation

If I want to customise a plot using iris.quickplot, I can modify every element after creating the plot EXCEPT the colorbar (due to how Matplotlib works).

@rcomer

This comment was marked as outdated.

@pp-mo
Copy link
Member

pp-mo commented May 24, 2024

I'm not quite sure of the exact scope or intention here, but I would probably oppose any additions to the quickplot api.
IMHO iris.quickplot is a quick + simple one-stop shop. If you need more control, you should simply be using iris.plot instead.
If there is still a need for additional controls there, to do things which can't be done otherwise, then I'd say that is appropriate.

@trexfeathers
Copy link
Contributor Author

From @SciTools/peloton:

We prefer the simpler solution of 1 new parameter: colorbar, which defaults to True. If the user wants a customised colorbar then they should use False then add their own after creating the plot.

@trexfeathers trexfeathers added the Good First Issue A good issue to take on if you're just getting started with Iris development label May 29, 2024
@rcomer
Copy link
Member

rcomer commented May 29, 2024

I think the work here is:

  1. Add the boolean colorbar keyword to the _label function, which controls whether the colorbar is added.

  2. Do the "plumbing" to expose the colorbar keyword in every public plotting function that ultimately calls _label.

  3. Add tests.

@ukmo-ccbunney
Copy link
Contributor

Just so I understand the problem, I assume it is not enough to have a handle to the colorbar instance so you can adjust stuff? E.g.:

cm = qplt.pcolormesh(cube)
cb = cm.colorbar

# change ticks:
cb.set_ticks( [ ... ] )

# change position:
cb.ax.set_position([ ... ])

@trexfeathers
Copy link
Contributor Author

trexfeathers commented Oct 8, 2024

Just so I understand the problem, I assume it is not enough to have a handle to the colorbar instance so you can adjust stuff?

I have been led to understand that it is not possible (at least not easy) to gain access to a colorbar that has already been added to the plot. Hence this being a problem.

@ukmo-ccbunney
Copy link
Contributor

ukmo-ccbunney commented Oct 8, 2024

Just so I understand the problem, I assume it is not enough to have a handle to the colorbar instance so you can adjust stuff?

I have been led to understand that it is not possible (at least not easy) to gain access to a colorbar that has already been added to the plot. Hence this being a problem.

It is straight forward to get a ref to the colorbar (as in the example I gave).
With this you can change the label, position, ticks, etc. for the colorbar.

However, I can't see a simple way to change the "orientation" though (which is one of the keywords passed in via plt.colorbar), so that alone might be a good reason to allow the user to create their own.

@rcomer
Copy link
Member

rcomer commented Oct 8, 2024

Note that this came from discussion #5964, where the user had a whole dictionary of colorbar keywords they wanted to specify. Unfortunately Colorbar is one of few Matplotlib objects that is not an Artist subclass, so is missing the set method.

@ukmo-ccbunney
Copy link
Contributor

Note that this came from discussion #5964, where the user had a whole dictionary of colorbar keywords they wanted to specify. Unfortunately Colorbar is one of few Matplotlib objects that is not an Artist subclass, so is missing the set method.

Thanks for the context @rcomer - that makes sense.
#6169 raised to address this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Good First Issue A good issue to take on if you're just getting started with Iris development
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

5 participants