2
2
Plotting Contour Subplots with different Colour Maps/Scales
3
3
============================================
4
4
In this recipe, we will plot data with different colour maps to illustrate
5
- the importance of choosing the correct one for a plot. This is to ensure
5
+ the importance of choosing the correct one for a plot. This is to ensure
6
6
the use of perceptually uniform scales and avoid unintended bias.
7
7
"""
8
8
13
13
14
14
import cf
15
15
16
- #%%
16
+ # %%
17
17
# 2. Read the field in:
18
- # Here I've used sample data ggap.nc (and later pressure=850), but you could use tas_A1.nc
18
+ # Here I've used sample data ggap.nc (and later pressure=850), but you could use tas_A1.nc
19
19
# (with time=15)
20
20
21
- f = cf .read (' ~/cfplot_data/ggap.nc' )[0 ]
21
+ f = cf .read (" ~/cfplot_data/ggap.nc" )[0 ]
22
22
23
- #%%
23
+ # %%
24
24
# 3. Choose a set of predefined colour scales to view (based on NCAR)
25
25
# Choose a set of predefined colour scales to view (based on NCAR)
26
- # You could also choose your own from
26
+ # You could also choose your own from
27
27
# https://ncas-cms.github.io/cf-plot/build/colour_scales.html
28
- # Simply change the name in quotes and ensure the number of rows * number of columns =
28
+ # Simply change the name in quotes and ensure the number of rows * number of columns =
29
29
# number of colour scales
30
30
31
- #%%
31
+ # %%
32
32
# a. Perceptually uniform colour scales, with no zero value
33
33
34
- colour_scale = ["viridis" , "magma" ,"inferno" , "plasma" , "parula" , "gray" ]
34
+ colour_scale = ["viridis" , "magma" , "inferno" , "plasma" , "parula" , "gray" ]
35
35
cfp .gopen (rows = 2 , columns = 3 , bottom = 0.2 )
36
36
37
- #%%
37
+ # %%
38
38
# b. NCAR Command Language - Enhanced to help with colour blindness
39
39
40
- colour_scale = ["StepSeq25" ,"posneg_2" ,"posneg_1" ,"BlueDarkOrange18" ,"BlueDarkRed18" ,
41
- "GreenMagenta16" ,"BlueGreen14" ,"BrownBlue12" ,"Cat12" ]
40
+ colour_scale = [
41
+ "StepSeq25" ,
42
+ "posneg_2" ,
43
+ "posneg_1" ,
44
+ "BlueDarkOrange18" ,
45
+ "BlueDarkRed18" ,
46
+ "GreenMagenta16" ,
47
+ "BlueGreen14" ,
48
+ "BrownBlue12" ,
49
+ "Cat12" ,
50
+ ]
42
51
cfp .gopen (rows = 3 , columns = 3 , bottom = 0.1 )
43
52
44
- #%%
53
+ # %%
45
54
# c. Orography/bathymetry colour scales
46
55
47
- # These are used to show the shape/contour of landmasses, bear in mind the example data
48
- # we use is with pressure so doesnt accurately represent this.
49
- # You could instead use cfp.cscale('wiki_2_0', ncols=16, below=2, above=14) or any other
56
+ # These are used to show the shape/contour of landmasses, bear in mind the example data
57
+ # we use is with pressure so doesnt accurately represent this.
58
+ # You could instead use cfp.cscale('wiki_2_0', ncols=16, below=2, above=14) or any other
50
59
# orography colour scale in a similar way
51
60
52
- colour_scale = ["os250kmetres" , "wiki_1_0_2" , "wiki_1_0_3" , "wiki_2_0" , "wiki_2_0_reduced" ,
53
- "arctic" ]
61
+ colour_scale = [
62
+ "os250kmetres" ,
63
+ "wiki_1_0_2" ,
64
+ "wiki_1_0_3" ,
65
+ "wiki_2_0" ,
66
+ "wiki_2_0_reduced" ,
67
+ "arctic" ,
68
+ ]
54
69
cfp .gopen (rows = 2 , columns = 3 , bottom = 0.2 , file = "ColourPlot.png" )
55
70
56
- #%%
71
+ # %%
57
72
# 5. We then use a for loop to cycle through all the different colour maps:
58
- # Only gpos has 1 added because it can only take 1 as its first value, otherwise there are
73
+ # Only gpos has 1 added because it can only take 1 as its first value, otherwise there are
59
74
# errors.
60
75
for i , colour_scale in enumerate (colour_scale ):
61
- cfp .gpos (i + 1 )
76
+ cfp .gpos (i + 1 )
62
77
cfp .mapset (proj = "cyl" )
63
78
cfp .cscale (colour_scale [i ])
64
- if i == len (colour_scale )+ 1 :
65
- cfp .con (f .subspace (pressure = 850 ), lines = False , title = colour_scale [i ], colorbar_position = [0.1 , 0.1 , 0.8 , 0.02 ], colorbar_orientation = 'horizontal' )
79
+ if i == len (colour_scale ) + 1 :
80
+ cfp .con (
81
+ f .subspace (pressure = 850 ),
82
+ lines = False ,
83
+ title = colour_scale [i ],
84
+ colorbar_position = [0.1 , 0.1 , 0.8 , 0.02 ],
85
+ colorbar_orientation = "horizontal" ,
86
+ )
66
87
else :
67
- cfp .con (f .subspace (pressure = 850 ), title = colour_scale [i ], lines = False )
68
- cfp .gclose (view = True )
88
+ cfp .con (f .subspace (pressure = 850 ), title = colour_scale [i ], lines = False )
89
+ cfp .gclose (view = True )
0 commit comments