Colour scales

There are two default colour scales in cf-plot:

  1. A continuous scale ('viridis') that goes from blue to green and then yellow and suits data that has no zero in it. For example air temperature in Kelvin or geopotential height - see example 1 in the plot gallery.

  2. A diverging scale ('scale1') that goes from blue to red and suits data with a zero in it. For example temperature in Celsius or zonal wind - see example 4 in the plot gallery. The colour scale is automatically adjusted so that blue hues are below zero and red hues above zero.

When no calls have been made to cfp.cscale cf-plot selects one of theses scales based on whether there is a zero in the data passed for contouring. If a call is made to cfp.cscale with just a colour scale name cfp.cscale('radar'), for example, then this colour scale is used for all subsequent plots. The colour scale is adjusted automatically to fit the number of contour levels in the plot.

If a call to cfp.cscale specifies additional parameters to the colour scale, then the automatic colour adjustment is turned off giving the user fine tuning of colours as below.

_images/cs1.png
cfp.levs(min=-80, max=80, step=10)
cfp.scale('scale1')


To change the number of colours in a scale use the ncols parameters.

_images/cs2.png
cfp.cscale('scale1', ncols=12)
cfp.levs(min=-5, max=5, step=1)


To change the number of colours above and below the mid-point of the scale use the above and below parameters. This is useful for fields where you have differing extents of data above and below the zero line.

_images/cs3.png
cfp.cscale('scale1', below=4, above=7)
cfp.levs(min=-30, max=60, step=10)


For data where you need white to indicate that this data region is insignificant use the white=white parameter. This can take single or multiple values of the index of the colour scale where white is required in the colour scale.

_images/cs4.png
cfp.cscale('scale1', ncols=11, white=5)
cfp.levs(manual=[-10,-8, -6, -4, -2, 2, 4, 6, 8, 10])
_images/cs4.png

To reverse a colour scale use the reverse=1 option to cscale and specify the number of colours required.

cfp.cscale('scale1', reverse=1, ncols=10)

As a short example to show the flexibilty of the colour scale routines we will make a orography plot using the wiki_2_0.rgb orography/bathymetry colour scale. This has as many colours for bathymetry as for the oroggraphy but in this case we just need a blue ocean as we are really only interested in the orography. So in this case we will define a set of levels using levs and then match the colour scale to them. The wiki_2_0.rgb colour scale has as many colours for the ocean as for the land so we can use the above and below options

_images/orog.png
import cf
import cfplot as cfp
import numpy as np
f=cf.read('cfplot_data/12km_orog.nc')[0]
cfp.cscale('wiki_2_0', ncols=16, below=2, above=14)
cfp.levs(manual=np.arange(15)*150)
cfp.con(f, lines=False)

User defined colour scales

Store these as rgb values in a file with one rgb value per line. i.e.

255 0   0
255 255 255
0   0   255

will give a red white blue colour scale. If the file is saved as /home/swsheaps/rwb.txt it is read in using

cfp.cscale('/home/swsheaps/rwb.txt')

Selecting colours for graph lines

This can be done in several ways:

  1. Select the colours from the Matplotlib colour names - Google 'Images for matplotlib color names'.

cfp.lineplot(g.subspace(pressure=925), color='plum')

  1. Use the hexadecimal code for the colour.

cfp.lineplot(g.subspace(pressure=925), color = '#eeefff')

  1. Shades of grey can be selected with cmap(shade), where shade go from 0 to 1.

cfp.lineplot(g.subspace(pressure=925), color=cmap(0.8))

Predefined colour scales

A lot of the following colour maps were downloaded from the NCAR Command Language web site. Users of the IDL guide colour maps can see these maps at the end of the colour scales.

Perceptually uniform colour scales

A selection of perceptually uniform colour scales for contouring data without a zero in. See The end of the rainbow and Matplotlib colour maps for a good discussion on colour scales, colour blindness and uniform colour scales.

Name

Scale

viridis

_images/viridis.png

magma

_images/magma.png

inferno

_images/inferno.png

plasma

_images/plasma.png

parula

_images/parula.png

gray

_images/gray.png

NCAR Command Language - MeteoSwiss colour maps

Name

Scale

hotcold_18lev

_images/hotcold_18lev.png

hotcolr_19lev

_images/hotcolr_19lev.png

mch_default

_images/mch_default.png

perc2_9lev

_images/perc2_9lev.png

percent_11lev

_images/percent_11lev.png

precip2_15lev

_images/precip2_15lev.png

precip2_17lev

_images/precip2_17lev.png

precip3_16lev

_images/precip3_16lev.png

precip4_11lev

_images/precip4_11lev.png

precip4_diff_19lev

_images/precip4_diff_19lev.png

precip_11lev

_images/precip_11lev.png

precip_diff_12lev

_images/precip_diff_12lev.png

precip_diff_1lev

_images/precip_diff_1lev.png

rh_19lev

_images/rh_19lev.png

spread_15lev

_images/spread_15lev.png

NCAR Command Language - small color maps (<50 colours)

Name

Scale

amwg

_images/amwg.png

amwg_blueyellowred

_images/amwg_blueyellowred.png

BlueDarkRed18

_images/BlueDarkRed18.png

BlueDarkOrange18

_images/BlueDarkOrange18.png

BlueGreen14

_images/BlueGreen14.png

BrownBlue12

_images/BrownBlue12.png

Cat12

_images/Cat12.png

cmp_flux

_images/cmp_flux.png

cosam12

_images/cosam12.png

cosam

_images/cosam.png

GHRSST_anomaly

_images/GHRSST_anomaly.png

GreenMagenta16

_images/GreenMagenta16.png

hotcold_18lev

_images/hotcold_18lev.png

hotcolr_19lev

_images/hotcolr_19lev.png

mch_default

_images/mch_default.png

nrl_sirkes

_images/nrl_sirkes.png

nrl_sirkes_nowhite

_images/nrl_sirkes_nowhite.png

perc2_9lev

_images/perc2_9lev.png

percent_11lev

_images/percent_11lev.png

posneg_2

_images/posneg_2.png

prcp_1

_images/prcp_1.png

prcp_2

_images/prcp_2.png

prcp_3

_images/prcp_3.png

precip_11lev

_images/precip_11lev.png

precip_diff_12lev

_images/precip_diff_12lev.png

precip_diff_1lev

_images/precip_diff_1lev.png

precip2_15lev

_images/precip2_15lev.png

precip2_17lev

_images/precip2_17lev.png

precip3_16lev

_images/precip3_16lev.png

precip4_11lev

_images/precip4_11lev.png

precip4_diff_19lev

_images/precip4_diff_19lev.png

radar

_images/radar.png

radar_1

_images/radar_1.png

rh_19lev

_images/rh_19lev.png

seaice_1

_images/seaice_1.png

seaice_2

_images/seaice_2.png

so4_21

_images/so4_21.png

spread_15lev

_images/spread_15lev.png

StepSeq25

_images/StepSeq25.png

sunshine_9lev

_images/sunshine_9lev.png

sunshine_diff_12lev

_images/sunshine_diff_12lev.png

temp_19lev

_images/temp_19lev.png

temp_diff_18lev

_images/temp_diff_18lev.png

temp_diff_1lev

_images/temp_diff_1lev.png

topo_15lev

_images/topo_15lev.png

wgne15

_images/wgne15.png

wind_17lev

_images/wind_17lev.png

NCAR Command Language - large colour maps (>50 colours)

Name

Scale

amwg256

_images/amwg256.png

BkBlAqGrYeOrReViWh200

_images/BkBlAqGrYeOrReViWh200.png

BlAqGrYeOrRe

_images/BlAqGrYeOrRe.png

BlAqGrYeOrReVi200

_images/BlAqGrYeOrReVi200.png

BlGrYeOrReVi200

_images/BlGrYeOrReVi200.png

BlRe

_images/BlRe.png

BlueRed

_images/BlueRed.png

BlueRedGray

_images/BlueRedGray.png

BlueWhiteOrangeRed

_images/BlueWhiteOrangeRed.png

BlueYellowRed

_images/BlueYellowRed.png

BlWhRe

_images/BlWhRe.png

cmp_b2r

_images/cmp_b2r.png

cmp_haxby

_images/cmp_haxby.png

detail

_images/detail.png

extrema

_images/extrema.png

GrayWhiteGray

_images/GrayWhiteGray.png

GreenYellow

_images/GreenYellow.png

helix

_images/helix.png

helix1

_images/helix1.png

hotres

_images/hotres.png

matlab_hot

_images/matlab_hot.png

matlab_hsv

_images/matlab_hsv.png

matlab_jet

_images/matlab_jet.png

matlab_lines

_images/matlab_lines.png

ncl_default

_images/ncl_default.png

ncview_default

_images/ncview_default.png

OceanLakeLandSnow

_images/OceanLakeLandSnow.png

rainbow

_images/rainbow.png

rainbow_white_gray

_images/rainbow_white_gray.png

rainbow_white

_images/rainbow_white.png

rainbow_gray

_images/rainbow_gray.png

tbr_240_300

_images/tbr_240_300.png

tbr_stdev_0_30

_images/tbr_stdev_0_30.png

tbr_var_0_500

_images/tbr_var_0_500.png

tbrAvg1

_images/tbrAvg1.png

tbrStd1

_images/tbrStd1.png

tbrVar1

_images/tbrVar1.png

thelix

_images/thelix.png

ViBlGrWhYeOrRe

_images/ViBlGrWhYeOrRe.png

wh_bl_gr_ye_re

_images/wh_bl_gr_ye_re.png

WhBlGrYeRe

_images/WhBlGrYeRe.png

WhBlReWh

_images/WhBlReWh.png

WhiteBlue

_images/WhiteBlue.png

WhiteBlueGreenYellowRed

_images/WhiteBlueGreenYellowRed.png

WhiteGreen

_images/WhiteGreen.png

WhiteYellowOrangeRed

_images/WhiteYellowOrangeRed.png

WhViBlGrYeOrRe

_images/WhViBlGrYeOrRe.png

WhViBlGrYeOrReWh

_images/WhViBlGrYeOrReWh.png

wxpEnIR

_images/wxpEnIR.png

3gauss

_images/3gauss.png

3saw

_images/3saw.png

BrBG

_images/BrBG.png

NCAR Command Language - Enhanced to help with colour blindness

Name

Scale

StepSeq25

_images/StepSeq25.png

posneg_2

_images/posneg_2.png

posneg_1

_images/posneg_1.png

BlueDarkOrange18

_images/BlueDarkOrange18.png

BlueDarkRed18

_images/BlueDarkRed18.png

GreenMagenta16

_images/GreenMagenta16.png

BlueGreen14

_images/BlueGreen14.png

BrownBlue12

_images/BrownBlue12.png

Cat12

_images/Cat12.png

Orography/bathymetry colour scales

Name

Scale

os250kmetres

_images/os250kmetres.png

wiki_1_0_2

_images/wiki_1_0_2.png

wiki_1_0_3

_images/wiki_1_0_3.png

wiki_2_0

_images/wiki_2_0.png

wiki_2_0_reduced

_images/wiki_2_0_reduced.png

arctic

_images/arctic.png

IDL guide scales

Name

Scale

scale1

_images/scale1.png

scale2

_images/scale2.png

scale3

_images/scale3.png

scale4

_images/scale4.png

scale5

_images/scale5.png

scale6

_images/scale6.png

scale7

_images/scale7.png

scale8

_images/scale8.png

scale9

_images/scale9.png

scale10

_images/scale10.png

scale11

_images/scale11.png

scale12

_images/scale12.png

scale13

_images/scale13.png

scale14

_images/scale14.png

scale15

_images/scale15.png

scale16

_images/scale16.png

scale17

_images/scale17.png

scale18

_images/scale18.png

scale19

_images/scale19.png

scale20

_images/scale20.png

scale21

_images/scale21.png

scale22

_images/scale22.png

scale23

_images/scale23.png

scale24

_images/scale24.png

scale25

_images/scale25.png

scale26

_images/scale26.png

scale27

_images/scale27.png

scale28

_images/scale28.png

scale29

_images/scale29.png

scale30

_images/scale30.png

scale31

_images/scale31.png

scale32

_images/scale32.png

scale33

_images/scale33.png

scale34

_images/scale34.png

scale35

_images/scale35.png

scale36

_images/scale36.png

scale37

_images/scale37.png

scale38

_images/scale38.png

scale39

_images/scale39.png

scale40

_images/scale40.png

scale41

_images/scale41.png

scale42

_images/scale42.png

scale43

_images/scale43.png

scale44

_images/scale44.png