Skip to content

Commit 21c3438

Browse files
Lint (black, isort, flake8) NH original recipe 17
1 parent ef5e740 commit 21c3438

File tree

1 file changed

+46
-25
lines changed

1 file changed

+46
-25
lines changed

docs/source/recipes/plot_17_recipe.py

Lines changed: 46 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Plotting Contour Subplots with different Colour Maps/Scales
33
============================================
44
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
66
the use of perceptually uniform scales and avoid unintended bias.
77
"""
88

@@ -13,56 +13,77 @@
1313

1414
import cf
1515

16-
#%%
16+
# %%
1717
# 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
1919
# (with time=15)
2020

21-
f=cf.read('~/cfplot_data/ggap.nc')[0]
21+
f = cf.read("~/cfplot_data/ggap.nc")[0]
2222

23-
#%%
23+
# %%
2424
# 3. Choose a set of predefined colour scales to view (based on NCAR)
2525
# 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
2727
# 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 =
2929
# number of colour scales
3030

31-
#%%
31+
# %%
3232
# a. Perceptually uniform colour scales, with no zero value
3333

34-
colour_scale = ["viridis", "magma","inferno", "plasma", "parula", "gray"]
34+
colour_scale = ["viridis", "magma", "inferno", "plasma", "parula", "gray"]
3535
cfp.gopen(rows=2, columns=3, bottom=0.2)
3636

37-
#%%
37+
# %%
3838
# b. NCAR Command Language - Enhanced to help with colour blindness
3939

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+
]
4251
cfp.gopen(rows=3, columns=3, bottom=0.1)
4352

44-
#%%
53+
# %%
4554
# c. Orography/bathymetry colour scales
4655

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
5059
# orography colour scale in a similar way
5160

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+
]
5469
cfp.gopen(rows=2, columns=3, bottom=0.2, file="ColourPlot.png")
5570

56-
#%%
71+
# %%
5772
# 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
5974
# errors.
6075
for i, colour_scale in enumerate(colour_scale):
61-
cfp.gpos(i+1)
76+
cfp.gpos(i + 1)
6277
cfp.mapset(proj="cyl")
6378
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+
)
6687
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

Comments
 (0)