Skip to content

Commit 046cf8f

Browse files
Natalia Huntsadielbartholomew
authored andcommitted
Add Natalia's recipe to showcase plotting projections
1 parent 39136ff commit 046cf8f

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
"""
2+
Plotting Contour Subplots with different Projections
3+
============================================
4+
In this recipe, we will plot different projections for the same data to illustrate
5+
visually the ones available in order to more visually decide which is suitable.
6+
"""
7+
8+
# %%
9+
# 1. Import cf-python and cf-plot:
10+
11+
import cfplot as cfp
12+
13+
import cf
14+
15+
#%%
16+
# 2. Read the field in:
17+
# Here I've used sample data ggap.nc (and later pressure=850),
18+
# but you could use tas_A1.nc (with time=15)
19+
20+
f=cf.read("~/cfplot_data/ggap.nc")[0]
21+
22+
#%%
23+
# 3. Create the file with subplots:
24+
# If you are changing the number of subplots ensure the number of rows * number
25+
# of columns = the number of subplots/projections
26+
# Here we are doing 6 projections so 2x3 is fine
27+
28+
cfp.gopen(rows=2, columns=3, bottom=0.2, file="projections.png")
29+
30+
#%%
31+
# 4. List the projection types being used:
32+
# Here we are using Cylindrical/Default, North Pole Stereographic,
33+
# South Pole Stereographic, Mollweide, Cropped Lambert Conformal and Robinson
34+
# However you could also use other such as "rotated", "ortho" or
35+
# "merc", "ukcp", "osgb", or "EuroPP"
36+
# https://ncas-cms.github.io/cf-plot/build/user_guide.html#appendixc
37+
38+
projtypes = ["cyl", "npstere", "spstere", "moll", "lcc", "robin"]
39+
40+
#%%
41+
# 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
43+
# errors. There are if statements for some projections (lcc, OSGB and EuroPP) as they have
44+
# specific requirements for their contour.
45+
# However, OSGB and EuroPP will require very different data anyway.
46+
47+
for i, proj in enumerate(projtypes):
48+
cfp.gpos(i+1)
49+
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')
53+
else:
54+
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
57+
else:
58+
cfp.con(f.subspace(pressure=850), lines = False, title = projtypes[i], colorbar = False)
59+
cfp.gclose()

0 commit comments

Comments
 (0)