From ef5e7406aec7af7681013adf791cd8898e964742 Mon Sep 17 00:00:00 2001 From: Natalia Hunt <> Date: Thu, 3 Oct 2024 23:24:42 +0100 Subject: [PATCH 01/11] Add Natalia's recipe to compare colour maps --- docs/source/recipes/plot_17_recipe.py | 68 +++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 docs/source/recipes/plot_17_recipe.py diff --git a/docs/source/recipes/plot_17_recipe.py b/docs/source/recipes/plot_17_recipe.py new file mode 100644 index 0000000000..2f625642d3 --- /dev/null +++ b/docs/source/recipes/plot_17_recipe.py @@ -0,0 +1,68 @@ +""" +Plotting Contour Subplots with different Colour Maps/Scales +============================================ +In this recipe, we will plot data with different colour maps to illustrate +the importance of choosing the correct one for a plot. This is to ensure +the use of perceptually uniform scales and avoid unintended bias. +""" + +# %% +# 1. Import cf-python and cf-plot: + +import cfplot as cfp + +import cf + +#%% +# 2. Read the field in: +# Here I've used sample data ggap.nc (and later pressure=850), but you could use tas_A1.nc +# (with time=15) + +f=cf.read('~/cfplot_data/ggap.nc')[0] + +#%% +# 3. Choose a set of predefined colour scales to view (based on NCAR) +# Choose a set of predefined colour scales to view (based on NCAR) +# You could also choose your own from +# https://ncas-cms.github.io/cf-plot/build/colour_scales.html +# Simply change the name in quotes and ensure the number of rows * number of columns = +# number of colour scales + +#%% +# a. Perceptually uniform colour scales, with no zero value + +colour_scale = ["viridis", "magma","inferno", "plasma", "parula", "gray"] +cfp.gopen(rows=2, columns=3, bottom=0.2) + +#%% +# b. NCAR Command Language - Enhanced to help with colour blindness + +colour_scale = ["StepSeq25","posneg_2","posneg_1","BlueDarkOrange18","BlueDarkRed18", +"GreenMagenta16","BlueGreen14","BrownBlue12","Cat12"] +cfp.gopen(rows=3, columns=3, bottom=0.1) + +#%% +# c. Orography/bathymetry colour scales + +# These are used to show the shape/contour of landmasses, bear in mind the example data +# we use is with pressure so doesnt accurately represent this. +# You could instead use cfp.cscale('wiki_2_0', ncols=16, below=2, above=14) or any other +# orography colour scale in a similar way + +colour_scale = ["os250kmetres", "wiki_1_0_2", "wiki_1_0_3", "wiki_2_0", "wiki_2_0_reduced", +"arctic"] +cfp.gopen(rows=2, columns=3, bottom=0.2, file="ColourPlot.png") + +#%% +# 5. We then use a for loop to cycle through all the different colour maps: +# Only gpos has 1 added because it can only take 1 as its first value, otherwise there are +# errors. +for i, colour_scale in enumerate(colour_scale): + cfp.gpos(i+1) + cfp.mapset(proj="cyl") + cfp.cscale(colour_scale[i]) + if i == len(colour_scale)+1: + 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') + else: + cfp.con(f.subspace(pressure=850), title = colour_scale[i], lines=False) +cfp.gclose(view=True) \ No newline at end of file From 21c3438e5dd1b395456ce21fa86bc24eff8ba908 Mon Sep 17 00:00:00 2001 From: "Sadie L. Bartholomew" Date: Thu, 3 Oct 2024 23:26:23 +0100 Subject: [PATCH 02/11] Lint (black, isort, flake8) NH original recipe 17 --- docs/source/recipes/plot_17_recipe.py | 71 +++++++++++++++++---------- 1 file changed, 46 insertions(+), 25 deletions(-) diff --git a/docs/source/recipes/plot_17_recipe.py b/docs/source/recipes/plot_17_recipe.py index 2f625642d3..0838ff93ce 100644 --- a/docs/source/recipes/plot_17_recipe.py +++ b/docs/source/recipes/plot_17_recipe.py @@ -2,7 +2,7 @@ Plotting Contour Subplots with different Colour Maps/Scales ============================================ In this recipe, we will plot data with different colour maps to illustrate -the importance of choosing the correct one for a plot. This is to ensure +the importance of choosing the correct one for a plot. This is to ensure the use of perceptually uniform scales and avoid unintended bias. """ @@ -13,56 +13,77 @@ import cf -#%% +# %% # 2. Read the field in: -# Here I've used sample data ggap.nc (and later pressure=850), but you could use tas_A1.nc +# Here I've used sample data ggap.nc (and later pressure=850), but you could use tas_A1.nc # (with time=15) -f=cf.read('~/cfplot_data/ggap.nc')[0] +f = cf.read("~/cfplot_data/ggap.nc")[0] -#%% +# %% # 3. Choose a set of predefined colour scales to view (based on NCAR) # Choose a set of predefined colour scales to view (based on NCAR) -# You could also choose your own from +# You could also choose your own from # https://ncas-cms.github.io/cf-plot/build/colour_scales.html -# Simply change the name in quotes and ensure the number of rows * number of columns = +# Simply change the name in quotes and ensure the number of rows * number of columns = # number of colour scales -#%% +# %% # a. Perceptually uniform colour scales, with no zero value -colour_scale = ["viridis", "magma","inferno", "plasma", "parula", "gray"] +colour_scale = ["viridis", "magma", "inferno", "plasma", "parula", "gray"] cfp.gopen(rows=2, columns=3, bottom=0.2) -#%% +# %% # b. NCAR Command Language - Enhanced to help with colour blindness -colour_scale = ["StepSeq25","posneg_2","posneg_1","BlueDarkOrange18","BlueDarkRed18", -"GreenMagenta16","BlueGreen14","BrownBlue12","Cat12"] +colour_scale = [ + "StepSeq25", + "posneg_2", + "posneg_1", + "BlueDarkOrange18", + "BlueDarkRed18", + "GreenMagenta16", + "BlueGreen14", + "BrownBlue12", + "Cat12", +] cfp.gopen(rows=3, columns=3, bottom=0.1) -#%% +# %% # c. Orography/bathymetry colour scales -# These are used to show the shape/contour of landmasses, bear in mind the example data -# we use is with pressure so doesnt accurately represent this. -# You could instead use cfp.cscale('wiki_2_0', ncols=16, below=2, above=14) or any other +# These are used to show the shape/contour of landmasses, bear in mind the example data +# we use is with pressure so doesnt accurately represent this. +# You could instead use cfp.cscale('wiki_2_0', ncols=16, below=2, above=14) or any other # orography colour scale in a similar way -colour_scale = ["os250kmetres", "wiki_1_0_2", "wiki_1_0_3", "wiki_2_0", "wiki_2_0_reduced", -"arctic"] +colour_scale = [ + "os250kmetres", + "wiki_1_0_2", + "wiki_1_0_3", + "wiki_2_0", + "wiki_2_0_reduced", + "arctic", +] cfp.gopen(rows=2, columns=3, bottom=0.2, file="ColourPlot.png") -#%% +# %% # 5. We then use a for loop to cycle through all the different colour maps: -# Only gpos has 1 added because it can only take 1 as its first value, otherwise there are +# Only gpos has 1 added because it can only take 1 as its first value, otherwise there are # errors. for i, colour_scale in enumerate(colour_scale): - cfp.gpos(i+1) + cfp.gpos(i + 1) cfp.mapset(proj="cyl") cfp.cscale(colour_scale[i]) - if i == len(colour_scale)+1: - 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') + if i == len(colour_scale) + 1: + 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", + ) else: - cfp.con(f.subspace(pressure=850), title = colour_scale[i], lines=False) -cfp.gclose(view=True) \ No newline at end of file + cfp.con(f.subspace(pressure=850), title=colour_scale[i], lines=False) +cfp.gclose(view=True) From d4cb7e32c310407745dee99b971860181855399e Mon Sep 17 00:00:00 2001 From: "Sadie L. Bartholomew" Date: Thu, 3 Oct 2024 23:54:07 +0100 Subject: [PATCH 03/11] Apply fix to logic in NH original recipe 17 --- docs/source/recipes/plot_17_recipe.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/docs/source/recipes/plot_17_recipe.py b/docs/source/recipes/plot_17_recipe.py index 0838ff93ce..a34f872c3a 100644 --- a/docs/source/recipes/plot_17_recipe.py +++ b/docs/source/recipes/plot_17_recipe.py @@ -18,7 +18,8 @@ # Here I've used sample data ggap.nc (and later pressure=850), but you could use tas_A1.nc # (with time=15) -f = cf.read("~/cfplot_data/ggap.nc")[0] +PATH="~/git-repos/cf-plot/cfplot/test/cfplot_data" +f = cf.read(f"{PATH}/ggap.nc")[0] # %% # 3. Choose a set of predefined colour scales to view (based on NCAR) @@ -75,15 +76,15 @@ for i, colour_scale in enumerate(colour_scale): cfp.gpos(i + 1) cfp.mapset(proj="cyl") - cfp.cscale(colour_scale[i]) + cfp.cscale(colour_scale) if i == len(colour_scale) + 1: cfp.con( f.subspace(pressure=850), lines=False, - title=colour_scale[i], + title=colour_scale, colorbar_position=[0.1, 0.1, 0.8, 0.02], colorbar_orientation="horizontal", ) else: - cfp.con(f.subspace(pressure=850), title=colour_scale[i], lines=False) + cfp.con(f.subspace(pressure=850), title=colour_scale, lines=False) cfp.gclose(view=True) From e18b90b654abbb150234161dbd82804f8984a920 Mon Sep 17 00:00:00 2001 From: "Sadie L. Bartholomew" Date: Fri, 4 Oct 2024 00:10:09 +0100 Subject: [PATCH 04/11] Apply line-wrapping & numbering fix NH original recipe 17 --- docs/source/recipes/plot_17_recipe.py | 33 ++++++++++++--------------- 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/docs/source/recipes/plot_17_recipe.py b/docs/source/recipes/plot_17_recipe.py index a34f872c3a..17112913eb 100644 --- a/docs/source/recipes/plot_17_recipe.py +++ b/docs/source/recipes/plot_17_recipe.py @@ -1,9 +1,11 @@ """ -Plotting Contour Subplots with different Colour Maps/Scales -============================================ +Plotting contour subplots with different colour maps/scales +=========================================================== + In this recipe, we will plot data with different colour maps to illustrate the importance of choosing the correct one for a plot. This is to ensure the use of perceptually uniform scales and avoid unintended bias. + """ # %% @@ -15,9 +17,8 @@ # %% # 2. Read the field in: -# Here I've used sample data ggap.nc (and later pressure=850), but you could use tas_A1.nc -# (with time=15) - +# Here I've used sample data ggap.nc (and later pressure=850), but you +# could use tas_A1.nc (with time=15) PATH="~/git-repos/cf-plot/cfplot/test/cfplot_data" f = cf.read(f"{PATH}/ggap.nc")[0] @@ -26,18 +27,16 @@ # Choose a set of predefined colour scales to view (based on NCAR) # You could also choose your own from # https://ncas-cms.github.io/cf-plot/build/colour_scales.html -# Simply change the name in quotes and ensure the number of rows * number of columns = -# number of colour scales +# Simply change the name in quotes and ensure the +# number of rows * number of columns = number of colour scales # %% # a. Perceptually uniform colour scales, with no zero value - colour_scale = ["viridis", "magma", "inferno", "plasma", "parula", "gray"] cfp.gopen(rows=2, columns=3, bottom=0.2) # %% # b. NCAR Command Language - Enhanced to help with colour blindness - colour_scale = [ "StepSeq25", "posneg_2", @@ -53,12 +52,10 @@ # %% # c. Orography/bathymetry colour scales - -# These are used to show the shape/contour of landmasses, bear in mind the example data -# we use is with pressure so doesnt accurately represent this. -# You could instead use cfp.cscale('wiki_2_0', ncols=16, below=2, above=14) or any other -# orography colour scale in a similar way - +# These are used to show the shape/contour of landmasses, bear in mind the +# example data we use is with pressure so doesnt accurately represent this. +# You could instead use cfp.cscale('wiki_2_0', ncols=16, below=2, above=14) +# or any other orography colour scale in a similar way. colour_scale = [ "os250kmetres", "wiki_1_0_2", @@ -70,9 +67,9 @@ cfp.gopen(rows=2, columns=3, bottom=0.2, file="ColourPlot.png") # %% -# 5. We then use a for loop to cycle through all the different colour maps: -# Only gpos has 1 added because it can only take 1 as its first value, otherwise there are -# errors. +# 4. We then use a for loop to cycle through all the different colour maps: +# Only gpos has 1 added because it can only take 1 as its first value, +# otherwise there are errors. for i, colour_scale in enumerate(colour_scale): cfp.gpos(i + 1) cfp.mapset(proj="cyl") From 43371e4845807d4063440046b42d65747d4de6e5 Mon Sep 17 00:00:00 2001 From: "Sadie L. Bartholomew" Date: Fri, 4 Oct 2024 17:14:33 +0100 Subject: [PATCH 05/11] Update NH original recipe 17 to show each cmap category w/ one plot --- docs/source/recipes/plot_17_recipe.py | 102 ++++++++++++++++++++------ 1 file changed, 80 insertions(+), 22 deletions(-) diff --git a/docs/source/recipes/plot_17_recipe.py b/docs/source/recipes/plot_17_recipe.py index 17112913eb..949aa91e6d 100644 --- a/docs/source/recipes/plot_17_recipe.py +++ b/docs/source/recipes/plot_17_recipe.py @@ -12,6 +12,7 @@ # 1. Import cf-python and cf-plot: import cfplot as cfp +import matplotlib.pyplot as plt import cf @@ -19,7 +20,7 @@ # 2. Read the field in: # Here I've used sample data ggap.nc (and later pressure=850), but you # could use tas_A1.nc (with time=15) -PATH="~/git-repos/cf-plot/cfplot/test/cfplot_data" +PATH = "~/git-repos/cf-plot/cfplot/test/cfplot_data" f = cf.read(f"{PATH}/ggap.nc")[0] # %% @@ -30,25 +31,30 @@ # Simply change the name in quotes and ensure the # number of rows * number of columns = number of colour scales + # %% # a. Perceptually uniform colour scales, with no zero value -colour_scale = ["viridis", "magma", "inferno", "plasma", "parula", "gray"] -cfp.gopen(rows=2, columns=3, bottom=0.2) +colour_scale_pu = [ + "viridis", + "magma", + "inferno", +] # "plasma", "parula", "gray"] + # %% # b. NCAR Command Language - Enhanced to help with colour blindness -colour_scale = [ +colour_scale_ncl = [ "StepSeq25", "posneg_2", - "posneg_1", - "BlueDarkOrange18", - "BlueDarkRed18", + # "posneg_1", + # "BlueDarkOrange18", + # "BlueDarkRed18", "GreenMagenta16", - "BlueGreen14", - "BrownBlue12", - "Cat12", + # "BlueGreen14", + # "BrownBlue12", + # "Cat12", ] -cfp.gopen(rows=3, columns=3, bottom=0.1) + # %% # c. Orography/bathymetry colour scales @@ -56,32 +62,84 @@ # example data we use is with pressure so doesnt accurately represent this. # You could instead use cfp.cscale('wiki_2_0', ncols=16, below=2, above=14) # or any other orography colour scale in a similar way. -colour_scale = [ +colour_scale_ob = [ "os250kmetres", "wiki_1_0_2", - "wiki_1_0_3", - "wiki_2_0", - "wiki_2_0_reduced", + # "wiki_1_0_3", + # "wiki_2_0", + # "wiki_2_0_reduced", "arctic", ] -cfp.gopen(rows=2, columns=3, bottom=0.2, file="ColourPlot.png") + +# We plot each category of colourmap as columns, but given the gpos +# function positions subplots from left to right, row by row from the top, +# we need to interleave the values in a list. We can use zip to do this. +# +colour_scales_columns = [ + val + for category in zip(colour_scale_pu, colour_scale_ncl, colour_scale_ob) + for val in category +] + +zip(colour_scale_pu, colour_scale_ncl, colour_scale_ob) # %% # 4. We then use a for loop to cycle through all the different colour maps: # Only gpos has 1 added because it can only take 1 as its first value, # otherwise there are errors. -for i, colour_scale in enumerate(colour_scale): +cfp.gopen(rows=3, columns=3, bottom=0.1, top=0.85, file="ColourPlot.png") +plt.suptitle( + ( + "Air temperature (K) at 850 mbar pressure shown in different " + "colourmap categories" + ), + fontsize=18, +) +for i, colour_scale in enumerate(colour_scales_columns): cfp.gpos(i + 1) - cfp.mapset(proj="cyl") cfp.cscale(colour_scale) if i == len(colour_scale) + 1: + # For the final plot, don't plot the colourbar across all subplots + # as is the default cfp.con( f.subspace(pressure=850), lines=False, - title=colour_scale, - colorbar_position=[0.1, 0.1, 0.8, 0.02], - colorbar_orientation="horizontal", + axes=False, + colorbar_drawedges=False, + colorbar_title=f"Shown in '{colour_scale}'", + colorbar_fraction=0.03, + colorbar_fontsize=11, ) + elif i < 3: + if i == 0: + set_title = "Perceptually uniform\ncolour maps" + elif i == 1: + set_title = ( + "NCL colour maps enhanced to \nhelp with colour blindness" + ) + elif i == 2: + set_title = "Orography/bathymetry\ncolour maps" + + cfp.con( + f.subspace(pressure=850), + lines=False, + axes=False, + title=set_title, + colorbar_drawedges=False, + colorbar_title=f"Shown in '{colour_scale}'", + colorbar_fraction=0.03, + colorbar_fontsize=11, + ) + else: - cfp.con(f.subspace(pressure=850), title=colour_scale, lines=False) + cfp.con( + f.subspace(pressure=850), + lines=False, + axes=False, + colorbar_drawedges=False, + colorbar_title=f"Shown in '{colour_scale}'", + colorbar_fontsize=11, + colorbar_fraction=0.03, + ) + cfp.gclose(view=True) From b962c8e3b0af2397b61e4e3c94ddecf2eae06cb8 Mon Sep 17 00:00:00 2001 From: "Sadie L. Bartholomew" Date: Fri, 4 Oct 2024 17:28:50 +0100 Subject: [PATCH 06/11] Select best representative cmaps for NH original recipe 17 --- docs/source/recipes/plot_17_recipe.py | 32 +++++++++------------------ 1 file changed, 11 insertions(+), 21 deletions(-) diff --git a/docs/source/recipes/plot_17_recipe.py b/docs/source/recipes/plot_17_recipe.py index 949aa91e6d..5f9e8e9884 100644 --- a/docs/source/recipes/plot_17_recipe.py +++ b/docs/source/recipes/plot_17_recipe.py @@ -34,25 +34,15 @@ # %% # a. Perceptually uniform colour scales, with no zero value -colour_scale_pu = [ - "viridis", - "magma", - "inferno", -] # "plasma", "parula", "gray"] +colour_scale_pu = ["viridis", "magma", "plasma"] # %% # b. NCAR Command Language - Enhanced to help with colour blindness colour_scale_ncl = [ - "StepSeq25", - "posneg_2", - # "posneg_1", - # "BlueDarkOrange18", - # "BlueDarkRed18", + "posneg_1", "GreenMagenta16", - # "BlueGreen14", - # "BrownBlue12", - # "Cat12", + "StepSeq25", ] @@ -63,12 +53,9 @@ # You could instead use cfp.cscale('wiki_2_0', ncols=16, below=2, above=14) # or any other orography colour scale in a similar way. colour_scale_ob = [ - "os250kmetres", "wiki_1_0_2", - # "wiki_1_0_3", - # "wiki_2_0", - # "wiki_2_0_reduced", - "arctic", + "wiki_2_0", + "wiki_2_0_reduced", ] @@ -107,7 +94,8 @@ axes=False, colorbar_drawedges=False, colorbar_title=f"Shown in '{colour_scale}'", - colorbar_fraction=0.03, + colorbar_fraction=0.04, + colorbar_thick=0.02, colorbar_fontsize=11, ) elif i < 3: @@ -127,7 +115,8 @@ title=set_title, colorbar_drawedges=False, colorbar_title=f"Shown in '{colour_scale}'", - colorbar_fraction=0.03, + colorbar_fraction=0.04, + colorbar_thick=0.02, colorbar_fontsize=11, ) @@ -138,8 +127,9 @@ axes=False, colorbar_drawedges=False, colorbar_title=f"Shown in '{colour_scale}'", + colorbar_fraction=0.04, + colorbar_thick=0.02, colorbar_fontsize=11, - colorbar_fraction=0.03, ) cfp.gclose(view=True) From 1259c9a7c0eba27c120a3e600605da6d12f09a82 Mon Sep 17 00:00:00 2001 From: "Sadie L. Bartholomew" Date: Fri, 4 Oct 2024 18:06:48 +0100 Subject: [PATCH 07/11] Code and comments simplification & tidy of NH recipe 17 --- docs/source/recipes/plot_17_recipe.py | 114 ++++++++++++-------------- 1 file changed, 52 insertions(+), 62 deletions(-) diff --git a/docs/source/recipes/plot_17_recipe.py b/docs/source/recipes/plot_17_recipe.py index 5f9e8e9884..7f5db0ddf4 100644 --- a/docs/source/recipes/plot_17_recipe.py +++ b/docs/source/recipes/plot_17_recipe.py @@ -2,10 +2,10 @@ Plotting contour subplots with different colour maps/scales =========================================================== -In this recipe, we will plot data with different colour maps to illustrate -the importance of choosing the correct one for a plot. This is to ensure -the use of perceptually uniform scales and avoid unintended bias. - +In this recipe, we will plot the same data with different colour maps from +three categories in separate subplots to illustrate the importance of +choosing a suitable one for given data. To avoid unintended bias and +misrepresentation, or lack of accessibility, a careful choice must be made. """ # %% @@ -18,87 +18,78 @@ # %% # 2. Read the field in: -# Here I've used sample data ggap.nc (and later pressure=850), but you -# could use tas_A1.nc (with time=15) PATH = "~/git-repos/cf-plot/cfplot/test/cfplot_data" f = cf.read(f"{PATH}/ggap.nc")[0] # %% -# 3. Choose a set of predefined colour scales to view (based on NCAR) -# Choose a set of predefined colour scales to view (based on NCAR) -# You could also choose your own from -# https://ncas-cms.github.io/cf-plot/build/colour_scales.html -# Simply change the name in quotes and ensure the -# number of rows * number of columns = number of colour scales - +# 3. Choose a set of predefined colour scales to view. These can be chosen +# from the selection at: +# https://ncas-cms.github.io/cf-plot/build/colour_scales.html or you +# can define your own, see: +# https://ncas-cms.github.io/cf-plot/build/colour_scales.html#user-defined-colour-scales. +# Here we take three colour scales each from three different general +# categories, to showcase some differences in representation. +# Note colour scale levels can be adjusted using 'cscale' and keywords such as: +# cfp.cscale(, ncols=16, below=2, above=14) # %% -# a. Perceptually uniform colour scales, with no zero value -colour_scale_pu = ["viridis", "magma", "plasma"] - +# a. Perceptually uniform colour scales, with no zero value, see: +# https://ncas-cms.github.io/cf-plot/build/colour_scales.html#perceptually-uniform-colour-scales. +colour_scales_pu = ["viridis", "magma", "plasma"] # %% -# b. NCAR Command Language - Enhanced to help with colour blindness -colour_scale_ncl = [ - "posneg_1", - "GreenMagenta16", - "StepSeq25", -] - +# b. NCAR Command Language colour scales enhanced to help with colour +# blindness, see: +# https://ncas-cms.github.io/cf-plot/build/colour_scales.html#ncar-command-language-enhanced-to-help-with-colour-blindness. +# These colour maps are better for accessibility. +colour_scales_ncl = ["posneg_1", "GreenMagenta16", "StepSeq25"] # %% -# c. Orography/bathymetry colour scales -# These are used to show the shape/contour of landmasses, bear in mind the -# example data we use is with pressure so doesnt accurately represent this. -# You could instead use cfp.cscale('wiki_2_0', ncols=16, below=2, above=14) -# or any other orography colour scale in a similar way. -colour_scale_ob = [ - "wiki_1_0_2", - "wiki_2_0", - "wiki_2_0_reduced", -] +# c. Orography/bathymetry colour scales, see: +# https://ncas-cms.github.io/cf-plot/build/colour_scales.html#orography-bathymetry-colour-scales. +# These are used to show the shape/contour of land masses, but bear in mind the +# data we show here is air temperature so doesn't represent this and +# therefore it is not a good choice in this case: +colour_scales_ob = ["wiki_1_0_2", "wiki_2_0", "wiki_2_0_reduced"] -# We plot each category of colourmap as columns, but given the gpos -# function positions subplots from left to right, row by row from the top, -# we need to interleave the values in a list. We can use zip to do this. -# +# %% +# 4. We plot each category of colourmap in a given columns of the subplot, +# but given the 'gpos' function positions subplots from left to right, row by +# row from the top, we need to interleave the values in a list. We can use +# zip to do this: colour_scales_columns = [ - val - for category in zip(colour_scale_pu, colour_scale_ncl, colour_scale_ob) - for val in category + cscale + for category in zip(colour_scales_pu, colour_scales_ncl, colour_scales_ob) + for cscale in category ] -zip(colour_scale_pu, colour_scale_ncl, colour_scale_ob) + # %% -# 4. We then use a for loop to cycle through all the different colour maps: -# Only gpos has 1 added because it can only take 1 as its first value, -# otherwise there are errors. -cfp.gopen(rows=3, columns=3, bottom=0.1, top=0.85, file="ColourPlot.png") +# 5. Create the figure and give it an overall title. Ensure the +# number of rows * number of columns = number of colour scales: +cfp.gopen(rows=3, columns=3, bottom=0.1, top=0.85, file="colour_scales.png") plt.suptitle( ( "Air temperature (K) at 850 mbar pressure shown in different " - "colourmap categories" + "categories of colour scale" ), fontsize=18, ) + +# %% +# 6. We loop through all the different colour maps defined and plot +# as subplots, with each category in the same column, labelling each column +# with the colour scale category: for i, colour_scale in enumerate(colour_scales_columns): cfp.gpos(i + 1) cfp.cscale(colour_scale) - if i == len(colour_scale) + 1: - # For the final plot, don't plot the colourbar across all subplots - # as is the default - cfp.con( - f.subspace(pressure=850), - lines=False, - axes=False, - colorbar_drawedges=False, - colorbar_title=f"Shown in '{colour_scale}'", - colorbar_fraction=0.04, - colorbar_thick=0.02, - colorbar_fontsize=11, - ) - elif i < 3: + + # For the topmost plots, label the coumn with the colour scale category + # using the 'title' argument, otherwise don't add a title. + if i < 3: + # Ensure the order the titles are written in corresponds to the + # order unzipped in step 4, so the columns match up correctly. if i == 0: set_title = "Perceptually uniform\ncolour maps" elif i == 1: @@ -110,16 +101,15 @@ cfp.con( f.subspace(pressure=850), + title=set_title, lines=False, axes=False, - title=set_title, colorbar_drawedges=False, colorbar_title=f"Shown in '{colour_scale}'", colorbar_fraction=0.04, colorbar_thick=0.02, colorbar_fontsize=11, ) - else: cfp.con( f.subspace(pressure=850), From 8c717a7442f8c765ba68c25f0847d717db934de1 Mon Sep 17 00:00:00 2001 From: "Sadie L. Bartholomew" Date: Fri, 4 Oct 2024 18:09:26 +0100 Subject: [PATCH 08/11] Standardise data IO paths for NH original recipe 16 --- docs/source/recipes/plot_17_recipe.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/docs/source/recipes/plot_17_recipe.py b/docs/source/recipes/plot_17_recipe.py index 7f5db0ddf4..17c77692d5 100644 --- a/docs/source/recipes/plot_17_recipe.py +++ b/docs/source/recipes/plot_17_recipe.py @@ -18,8 +18,7 @@ # %% # 2. Read the field in: -PATH = "~/git-repos/cf-plot/cfplot/test/cfplot_data" -f = cf.read(f"{PATH}/ggap.nc")[0] +f = cf.read(f"~/recipes/ggap.nc")[0] # %% # 3. Choose a set of predefined colour scales to view. These can be chosen @@ -68,7 +67,7 @@ # %% # 5. Create the figure and give it an overall title. Ensure the # number of rows * number of columns = number of colour scales: -cfp.gopen(rows=3, columns=3, bottom=0.1, top=0.85, file="colour_scales.png") +cfp.gopen(rows=3, columns=3, bottom=0.1, top=0.85) plt.suptitle( ( "Air temperature (K) at 850 mbar pressure shown in different " From 390a7c9aa36ed72466cc3bc72553b66bb32b144c Mon Sep 17 00:00:00 2001 From: "Sadie L. Bartholomew" Date: Tue, 8 Oct 2024 13:54:55 +0100 Subject: [PATCH 09/11] Self-review: simplify logic in updated Natalia recipe 17 --- docs/source/recipes/plot_17_recipe.py | 58 +++++++++++---------------- 1 file changed, 24 insertions(+), 34 deletions(-) diff --git a/docs/source/recipes/plot_17_recipe.py b/docs/source/recipes/plot_17_recipe.py index 17c77692d5..0738c62a3a 100644 --- a/docs/source/recipes/plot_17_recipe.py +++ b/docs/source/recipes/plot_17_recipe.py @@ -18,7 +18,7 @@ # %% # 2. Read the field in: -f = cf.read(f"~/recipes/ggap.nc")[0] +f = cf.read("~/recipes/ggap.nc")[0] # %% # 3. Choose a set of predefined colour scales to view. These can be chosen @@ -84,41 +84,31 @@ cfp.gpos(i + 1) cfp.cscale(colour_scale) - # For the topmost plots, label the coumn with the colour scale category + # For the topmost plots, label the column with the colour scale category # using the 'title' argument, otherwise don't add a title. - if i < 3: - # Ensure the order the titles are written in corresponds to the - # order unzipped in step 4, so the columns match up correctly. - if i == 0: - set_title = "Perceptually uniform\ncolour maps" - elif i == 1: - set_title = ( - "NCL colour maps enhanced to \nhelp with colour blindness" - ) - elif i == 2: - set_title = "Orography/bathymetry\ncolour maps" - - cfp.con( - f.subspace(pressure=850), - title=set_title, - lines=False, - axes=False, - colorbar_drawedges=False, - colorbar_title=f"Shown in '{colour_scale}'", - colorbar_fraction=0.04, - colorbar_thick=0.02, - colorbar_fontsize=11, + # Ensure the order the titles are written in corresponds to the + # order unzipped in step 4, so the columns match up correctly. + if i == 0: + set_title = "Perceptually uniform\ncolour maps" + elif i == 1: + set_title = ( + "NCL colour maps enhanced to \nhelp with colour blindness" ) + elif i == 2: + set_title = "Orography/bathymetry\ncolour maps" else: - cfp.con( - f.subspace(pressure=850), - lines=False, - axes=False, - colorbar_drawedges=False, - colorbar_title=f"Shown in '{colour_scale}'", - colorbar_fraction=0.04, - colorbar_thick=0.02, - colorbar_fontsize=11, - ) + set_title = "" + + cfp.con( + f.subspace(pressure=850), + title=set_title, + lines=False, + axes=False, + colorbar_drawedges=False, + colorbar_title=f"Shown in '{colour_scale}'", + colorbar_fraction=0.04, + colorbar_thick=0.02, + colorbar_fontsize=11, + ) cfp.gclose(view=True) From f467e1f72e00e3cc4f9a4aa23ed453ca0cf8634a Mon Sep 17 00:00:00 2001 From: "Sadie L. Bartholomew" Date: Tue, 8 Oct 2024 13:58:43 +0100 Subject: [PATCH 10/11] Update recipe_list document to list Natalia recipe 17 --- docs/source/recipes/recipe_list.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/source/recipes/recipe_list.txt b/docs/source/recipes/recipe_list.txt index f39297f9cb..7fb7400b7d 100644 --- a/docs/source/recipes/recipe_list.txt +++ b/docs/source/recipes/recipe_list.txt @@ -27,4 +27,6 @@ plot_13_recipe.html#sphx-glr-recipes-plot-13-recipe-py plot_14_recipe.html#sphx-glr-recipes-plot-14-recipe-py
plot_15_recipe.html#sphx-glr-recipes-plot-15-recipe-py -
\ No newline at end of file +
+plot_17_recipe.html#sphx-glr-recipes-plot-17-recipe-py +
From 432ab049eadfb0906caa14869ee68e956ba35f4f Mon Sep 17 00:00:00 2001 From: "Sadie L. Bartholomew" Date: Thu, 10 Oct 2024 15:33:57 +0100 Subject: [PATCH 11/11] Fix classes attached to recipe 17 filter keywords --- docs/source/recipes/recipe_list.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/recipes/recipe_list.txt b/docs/source/recipes/recipe_list.txt index 7fb7400b7d..d93193c0a5 100644 --- a/docs/source/recipes/recipe_list.txt +++ b/docs/source/recipes/recipe_list.txt @@ -29,4 +29,4 @@ plot_14_recipe.html#sphx-glr-recipes-plot-14-recipe-py plot_15_recipe.html#sphx-glr-recipes-plot-15-recipe-py
plot_17_recipe.html#sphx-glr-recipes-plot-17-recipe-py -
+