Skip to content

Commit 82021ee

Browse files
Lint (black, isort, flake8) NH original recipe 16
1 parent 046cf8f commit 82021ee

File tree

1 file changed

+32
-21
lines changed

1 file changed

+32
-21
lines changed
Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
Plotting Contour Subplots with different Projections
3-
============================================
3+
====================================================
4+
45
In this recipe, we will plot different projections for the same data to illustrate
56
visually the ones available in order to more visually decide which is suitable.
67
"""
@@ -9,51 +10,61 @@
910
# 1. Import cf-python and cf-plot:
1011

1112
import cfplot as cfp
12-
1313
import cf
1414

15-
#%%
15+
# %%
1616
# 2. Read the field in:
17-
# Here I've used sample data ggap.nc (and later pressure=850),
17+
# Here I've used sample data ggap.nc (and later pressure=850),
1818
# but you could use tas_A1.nc (with time=15)
1919

20-
f=cf.read("~/cfplot_data/ggap.nc")[0]
20+
f = cf.read("~/cfplot_data/ggap.nc")[0]
2121

22-
#%%
22+
# %%
2323
# 3. Create the file with subplots:
24-
# If you are changing the number of subplots ensure the number of rows * number
24+
# If you are changing the number of subplots ensure the number of rows * number
2525
# of columns = the number of subplots/projections
2626
# Here we are doing 6 projections so 2x3 is fine
2727

2828
cfp.gopen(rows=2, columns=3, bottom=0.2, file="projections.png")
2929

30-
#%%
30+
# %%
3131
# 4. List the projection types being used:
32-
# Here we are using Cylindrical/Default, North Pole Stereographic,
32+
# Here we are using Cylindrical/Default, North Pole Stereographic,
3333
# South Pole Stereographic, Mollweide, Cropped Lambert Conformal and Robinson
34-
# However you could also use other such as "rotated", "ortho" or
34+
# However you could also use other such as "rotated", "ortho" or
3535
# "merc", "ukcp", "osgb", or "EuroPP"
3636
# https://ncas-cms.github.io/cf-plot/build/user_guide.html#appendixc
3737

38-
projtypes = ["cyl", "npstere", "spstere", "moll", "lcc", "robin"]
38+
projtypes = ["cyl", "npstere", "spstere", "moll", "lcc", "robin"]
3939

40-
#%%
40+
# %%
4141
# 5. We then use a for loop to cycle through all the different projection types:
42-
# Only gpos has 1 added because it can only take 1 as its first value, otherwise there are
42+
# Only gpos has 1 added because it can only take 1 as its first value, otherwise there are
4343
# errors. There are if statements for some projections (lcc, OSGB and EuroPP) as they have
4444
# specific requirements for their contour.
4545
# However, OSGB and EuroPP will require very different data anyway.
4646

4747
for i, proj in enumerate(projtypes):
48-
cfp.gpos(i+1)
48+
cfp.gpos(i + 1)
4949
if projtypes[i] == "lcc":
50-
cfp.mapset(proj='lcc', lonmin=-50, lonmax=50, latmin=20, latmax=85)
51-
if (projtypes[i]== "OSGB") or (projtypes[i] =="EuroPP"):
52-
cfp.mapset(proj=projtypes[i], resolution='50m')
50+
cfp.mapset(proj="lcc", lonmin=-50, lonmax=50, latmin=20, latmax=85)
51+
if (projtypes[i] == "OSGB") or (projtypes[i] == "EuroPP"):
52+
cfp.mapset(proj=projtypes[i], resolution="50m")
5353
else:
5454
cfp.mapset(proj=projtypes[i])
55-
if i ==len(projtypes)-1:
56-
cfp.con(f.subspace(pressure=850), lines=False, title = projtypes[i], colorbar_position=[0.1, 0.1, 0.8, 0.02], colorbar_orientation='horizontal') #to see the marking lines need to be True, but this can be hard to read so if not needed use False
55+
if i == len(projtypes) - 1:
56+
cfp.con(
57+
f.subspace(pressure=850),
58+
lines=False,
59+
title=projtypes[i],
60+
colorbar_position=[0.1, 0.1, 0.8, 0.02],
61+
colorbar_orientation="horizontal",
62+
) # to see the marking lines need to be True, but this can be hard to read so if not needed use False
5763
else:
58-
cfp.con(f.subspace(pressure=850), lines = False, title = projtypes[i], colorbar = False)
59-
cfp.gclose()
64+
cfp.con(
65+
f.subspace(pressure=850),
66+
lines=False,
67+
title=projtypes[i],
68+
colorbar=False,
69+
)
70+
cfp.gclose()

0 commit comments

Comments
 (0)