-
Notifications
You must be signed in to change notification settings - Fork 68
CDAT 3.0 Compatibility Workarounds
With the upcoming release of CDAT 3.0, a number of changes are being made that may require changes in your code to achieve the same behavior as in 2.X and earlier. Documented here are the suggested workarounds to these problems, and the motivation for making the change.
Recently, we changed the default range for colors from 16-240 to 0-255. This was part of the changeover of the default colormap to Viridis (option D), and made possible by the color changes made in 2.4 (more on that here). Previously, the colors between 0-16 and 241-255 were reserved for "system" colors (black, white, etc.) so that templates and split colormaps could take advantage of them. Now we have color literals (as documented in the previous link), so we don't need to take up that space in the colormap any more. The upshot of this is that you get more room to work with in your colormaps; the downside is that any use of the old colormaps that relied on automatic color selection may run into some issues out-of-the-box. Any colors manually specified will remain exactly the same.
If you find that you are having trouble with colors not displaying properly, this may be the cause. If your colorbar has odd colors at the beginning or end, you can use this to make the plots show up normally again.
colormap = "rainbow"
if colormap in ['AMIP',
'NCAR',
'bl_to_darkred',
'bl_to_drkorang',
'blends',
'blue2darkorange',
'blue2darkred',
'blue2green',
'blue2grey',
'blue2orange',
'blue2orange2red',
'blue_to_grey',
'blue_to_grn',
'blue_to_orange',
'blue_to_orgred',
'brown2blue',
'brown_to_blue',
'categorical',
'classic',
'green2magenta',
'grn_to_magenta',
'inferno',
'lightblue2darkblue',
'ltbl_to_drkbl',
'rainbow',
'rainbow_no_grn',
'rainbownogreen',
'sequential',
'white2blue',
'white2green',
'white2magenta',
'white2red',
'white2yellow',
'white_to_blue',
'white_to_green',
'white_to_magenta',
'white_to_red',
'white_to_yellow']:
# Restore old behaviour of default colors for old colormaps
vcs.utils.defaultColorsRange = range(16,240)
...
boxfill.colormap = colormap
canvas.plot(variable, boxfill)
Note that if you want to use any of the new colormaps (viridis, inferno, magma, plasma), you should use the new defaults.