Skip to content

Commit

Permalink
Apply line-wrapping & numbering fix NH original recipe 17
Browse files Browse the repository at this point in the history
  • Loading branch information
sadielbartholomew committed Oct 3, 2024
1 parent d4cb7e3 commit e18b90b
Showing 1 changed file with 15 additions and 18 deletions.
33 changes: 15 additions & 18 deletions docs/source/recipes/plot_17_recipe.py
Original file line number Diff line number Diff line change
@@ -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.
"""

# %%
Expand All @@ -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]

Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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")
Expand Down

0 comments on commit e18b90b

Please sign in to comment.