NCAS-CMS / cf-plot

Code-light plotting for earth science and aligned research
https://ncas-cms.github.io/cf-plot/build/
MIT License
12 stars 8 forks source link

Default colourbar `extend='max'` when minimum level or value is zero #44

Open sadielbartholomew opened 6 months ago

sadielbartholomew commented 6 months ago

cf-plot has an 'extend' keyword option to cbar, levs and to specific functions to enable or disable extension markers on each end of the displayed colour bar, which is set by default to be enabled at both ends:

https://github.com/NCAS-CMS/cf-plot/blob/a325942415561e5a22773715ff3946e1416094f7/cfplot/cfplot.py#L8618-L8619

which produces colour bar ends like this (see red annotations):

example_1_extend

However, in practice I have seen people show plots in presentations where the values plotted start at zero where the extension marker is still at the lower end. This made me think that we should update our default behaviour.

Namely, given very often when data values begin at 0(.0) that means the data in question doesn't make physical sense as a negative value, e.g. for a ratio or fraction such as albedo, for a vector magnitude such as wind magnitude, or for a scalar quantity such as mass which has no meaning in negative terms.

In these cases by default we still show the extension markers on the lower end, which is misleading data visualisation (and as much as the user should change this on the plot to correct it, often I have seen this hasn't been done - maybe they didn't have the time, or weren't aware that cf-plot allows one to configure this). In these cases, the colour bar should have extend='max' as the default behaviour, so that only the colour bar upper end gets the extension marker end:

example_2_extend

(Note this would only be default behaviour, and can still be overridden by the user in case the range of possible values does extend below zero and they just happen to want to show the levels beginning with zero.)

davidhassell commented 6 months ago

Hi Sadie - I'm not sure about treating zero as a special case (if I understand correctly). Wouldn't it be better to compare the data minimum with the colour bar mininum and (by default) add the extension triangle only if the former is greater than the larger? Similarly for the maximum.

sadielbartholomew commented 6 months ago

Hi @davidhassell. Yes, you do understand correctly, I believe zero should be a special case, for the reasons I outline, notably (the 'TLDR' key bit):

when data values begin at 0(.0) that means the data in question doesn't make physical sense as a negative value, e.g. for a ratio or fraction such as albedo, for a vector magnitude such as wind magnitude, or for a scalar quantity such as mass which has no meaning in negative terms.

Fair enough that you disagree (or question) this! I like your alternative suggestion, though I want to play around with some real datasets and plots of them to convince myself it will produce sensible extension markers, or lack thereof, in the majority of cases. Thanks, I'll keep you updated here once I have time to start tackling this.