iris
iris copied to clipboard
Configurable colorbar in `iris.quickplot`
✨ 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).
I think the work here is:
-
Add a
colorbar_kwargskeyword to the_labelfunction, which is a dictionary of keywords to use in thecolorbarcall. 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, theset_labelcall should be skipped. -
Do the "plumbing" to expose
colorbar_kwargsin every public plotting function that ultimately calls_label. -
Add tests.
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.
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.
I think the work here is:
-
Add the boolean
colorbarkeyword to the_labelfunction, which controls whether the colorbar is added. -
Do the "plumbing" to expose the
colorbarkeyword in every public plotting function that ultimately calls_label. -
Add tests.
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([ ... ])
Just so I understand the problem, I assume it is not enough to have a handle to the
colorbarinstance 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.
Just so I understand the problem, I assume it is not enough to have a handle to the
colorbarinstance 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
colorbarthat 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.
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.
Note that this came from discussion #5964, where the user had a whole dictionary of colorbar keywords they wanted to specify. Unfortunately
Colorbaris one of few Matplotlib objects that is not anArtistsubclass, so is missing the set method.
Thanks for the context @rcomer - that makes sense. #6169 raised to address this.