|
1 | 1 | """
|
2 |
| -Plotting Contour Subplots with different Colour Maps/Scales |
3 |
| -============================================ |
| 2 | +Plotting contour subplots with different colour maps/scales |
| 3 | +=========================================================== |
| 4 | +
|
4 | 5 | In this recipe, we will plot data with different colour maps to illustrate
|
5 | 6 | the importance of choosing the correct one for a plot. This is to ensure
|
6 | 7 | the use of perceptually uniform scales and avoid unintended bias.
|
| 8 | +
|
7 | 9 | """
|
8 | 10 |
|
9 | 11 | # %%
|
|
15 | 17 |
|
16 | 18 | # %%
|
17 | 19 | # 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 |
19 |
| -# (with time=15) |
20 |
| - |
| 20 | +# Here I've used sample data ggap.nc (and later pressure=850), but you |
| 21 | +# could use tas_A1.nc (with time=15) |
21 | 22 | PATH="~/git-repos/cf-plot/cfplot/test/cfplot_data"
|
22 | 23 | f = cf.read(f"{PATH}/ggap.nc")[0]
|
23 | 24 |
|
|
26 | 27 | # Choose a set of predefined colour scales to view (based on NCAR)
|
27 | 28 | # You could also choose your own from
|
28 | 29 | # https://ncas-cms.github.io/cf-plot/build/colour_scales.html
|
29 |
| -# Simply change the name in quotes and ensure the number of rows * number of columns = |
30 |
| -# number of colour scales |
| 30 | +# Simply change the name in quotes and ensure the |
| 31 | +# number of rows * number of columns = number of colour scales |
31 | 32 |
|
32 | 33 | # %%
|
33 | 34 | # a. Perceptually uniform colour scales, with no zero value
|
34 |
| - |
35 | 35 | colour_scale = ["viridis", "magma", "inferno", "plasma", "parula", "gray"]
|
36 | 36 | cfp.gopen(rows=2, columns=3, bottom=0.2)
|
37 | 37 |
|
38 | 38 | # %%
|
39 | 39 | # b. NCAR Command Language - Enhanced to help with colour blindness
|
40 |
| - |
41 | 40 | colour_scale = [
|
42 | 41 | "StepSeq25",
|
43 | 42 | "posneg_2",
|
|
53 | 52 |
|
54 | 53 | # %%
|
55 | 54 | # c. Orography/bathymetry colour scales
|
56 |
| - |
57 |
| -# These are used to show the shape/contour of landmasses, bear in mind the example data |
58 |
| -# we use is with pressure so doesnt accurately represent this. |
59 |
| -# You could instead use cfp.cscale('wiki_2_0', ncols=16, below=2, above=14) or any other |
60 |
| -# orography colour scale in a similar way |
61 |
| - |
| 55 | +# These are used to show the shape/contour of landmasses, bear in mind the |
| 56 | +# example data we use is with pressure so doesnt accurately represent this. |
| 57 | +# You could instead use cfp.cscale('wiki_2_0', ncols=16, below=2, above=14) |
| 58 | +# or any other orography colour scale in a similar way. |
62 | 59 | colour_scale = [
|
63 | 60 | "os250kmetres",
|
64 | 61 | "wiki_1_0_2",
|
|
70 | 67 | cfp.gopen(rows=2, columns=3, bottom=0.2, file="ColourPlot.png")
|
71 | 68 |
|
72 | 69 | # %%
|
73 |
| -# 5. We then use a for loop to cycle through all the different colour maps: |
74 |
| -# Only gpos has 1 added because it can only take 1 as its first value, otherwise there are |
75 |
| -# errors. |
| 70 | +# 4. We then use a for loop to cycle through all the different colour maps: |
| 71 | +# Only gpos has 1 added because it can only take 1 as its first value, |
| 72 | +# otherwise there are errors. |
76 | 73 | for i, colour_scale in enumerate(colour_scale):
|
77 | 74 | cfp.gpos(i + 1)
|
78 | 75 | cfp.mapset(proj="cyl")
|
|
0 commit comments