Skip to content

Commit ac9ce15

Browse files
Merge pull request #818 from sadielbartholomew/student-reipces-1
Add new recipe (16) by summer student: projection subplots
2 parents 9bb47a0 + a9efead commit ac9ce15

File tree

2 files changed

+63
-2
lines changed

2 files changed

+63
-2
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+
5+
In this recipe, we will plot the same data using different projections
6+
as subplots to illustrate visually some available possibilities.
7+
8+
"""
9+
10+
# %%
11+
# 1. Import cf-python and cf-plot:
12+
13+
import cfplot as cfp
14+
15+
import cf
16+
17+
# %%
18+
# 2. Read the field in:
19+
f = cf.read("~/recipes/ggap.nc")[0]
20+
21+
# %%
22+
# 3. Create the file with subplots. If changing the number of subplots,
23+
# ensure the number of rows * number of columns = the number of projections.
24+
# Here we are doing 6 projections so 2 x 3 is fine:
25+
cfp.gopen(rows=2, columns=3, bottom=0.2, file="projections.png")
26+
27+
# %%
28+
# 4. List the projection types to use. Here we are using
29+
# Cylindrical/Default, North Pole Stereographic, South Pole Stereographic,
30+
# Mollweide, Mercator and Robinson. However there are several other choices
31+
# possible, see:
32+
# https://ncas-cms.github.io/cf-plot/build/user_guide.html#appendixc. Our
33+
# chosen list is:
34+
projtypes = ["cyl", "npstere", "spstere", "moll", "merc", "robin"]
35+
36+
# %%
37+
# 5. Loop through the list of projection types and plot each as a sub-plot:
38+
for i, proj in enumerate(projtypes):
39+
# gpos has 1 added to the index because it takes 1 as its first value
40+
cfp.gpos(i + 1)
41+
cfp.mapset(proj=proj)
42+
43+
# For the final plot only, add a colour bar to cover all the sub-plots
44+
if i == len(projtypes) - 1:
45+
cfp.con(
46+
f.subspace(pressure=850),
47+
lines=False,
48+
title=proj,
49+
colorbar_position=[0.1, 0.1, 0.8, 0.02],
50+
colorbar_orientation="horizontal",
51+
)
52+
else:
53+
cfp.con(
54+
f.subspace(pressure=850),
55+
lines=False,
56+
title=proj,
57+
colorbar=False,
58+
)
59+
cfp.gclose()

docs/source/recipes/recipe_list.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ plot_06_recipe.html#sphx-glr-recipes-plot-06-recipe-py
1313
plot_07_recipe.html#sphx-glr-recipes-plot-07-recipe-py
1414
<div class="sphx-glr-thumbcontainer aggregate lineplot subspace" tooltip="Aggregate, Lineplot, Subspace">
1515
plot_08_recipe.html#sphx-glr-recipes-plot-08-recipe-py
16-
<div class="sphx-glr-thumbcontainer collapse contourmap" tooltip="Collapse, Contourmap">
16+
<div class="sphx-glr-thumbcontainer collapse contourmap" tooltip="Collapse, Contourmap, Subplot">
1717
plot_09_recipe.html#sphx-glr-recipes-plot-09-recipe-py
1818
<div class="sphx-glr-thumbcontainer histogram" tooltip="Histogram">
1919
plot_10_recipe.html#sphx-glr-recipes-plot-10-recipe-py
@@ -27,4 +27,6 @@ plot_13_recipe.html#sphx-glr-recipes-plot-13-recipe-py
2727
plot_14_recipe.html#sphx-glr-recipes-plot-14-recipe-py
2828
<div class="sphx-glr-thumbcontainer subspace collapse contourmap" tooltip="Subspace, Collapse, Contourmap">
2929
plot_15_recipe.html#sphx-glr-recipes-plot-15-recipe-py
30-
<div class="sphx-glr-thumbcontainer histogram subspace" tooltip="Histogram, Subspace">
30+
<div class="sphx-glr-thumbcontainer histogram subspace" tooltip="Histogram, Subspace, Subplot">
31+
plot_16_recipe.html#sphx-glr-recipes-plot-16-recipe-py
32+
<div class="sphx-glr-thumbcontainer contourmap subspace subplot" tooltip="Contourmap, Subspace, Subplot">

0 commit comments

Comments
 (0)