iris icon indicating copy to clipboard operation
iris copied to clipboard

Configurable colorbar in `iris.quickplot`

Open trexfeathers opened this issue 1 year ago • 4 comments

✨ 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).

trexfeathers avatar May 22 '24 09:05 trexfeathers

I think the work here is:

  1. Add a colorbar_kwargs keyword to the _label function, which is a dictionary of keywords to use in the colorbar call. If "orientation" or "drawedges" is in that dictionary, they should override the current choices. If "location" is in the dictionary, then "orientation" should not be passed. If "label" is in the dictionary, the set_label call should be skipped.

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

  3. Add tests.

rcomer avatar May 22 '24 11:05 rcomer

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.

pp-mo avatar May 24 '24 15:05 pp-mo

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 avatar May 29 '24 09:05 trexfeathers

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.

rcomer avatar May 29 '24 09:05 rcomer

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([ ... ])

ukmo-ccbunney avatar Oct 08 '24 15:10 ukmo-ccbunney

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.

trexfeathers avatar Oct 08 '24 15:10 trexfeathers

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.

ukmo-ccbunney avatar Oct 08 '24 16:10 ukmo-ccbunney

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.

rcomer avatar Oct 08 '24 16:10 rcomer

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.

ukmo-ccbunney avatar Oct 09 '24 09:10 ukmo-ccbunney