Skip to content

Commit

Permalink
Merge pull request #818 from sadielbartholomew/student-reipces-1
Browse files Browse the repository at this point in the history
Add new recipe (16) by summer student: projection subplots
  • Loading branch information
sadielbartholomew authored Nov 8, 2024
2 parents 9bb47a0 + a9efead commit ac9ce15
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 2 deletions.
59 changes: 59 additions & 0 deletions docs/source/recipes/plot_16_recipe.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
"""
Plotting contour subplots with different projections
====================================================
In this recipe, we will plot the same data using different projections
as subplots to illustrate visually some available possibilities.
"""

# %%
# 1. Import cf-python and cf-plot:

import cfplot as cfp

import cf

# %%
# 2. Read the field in:
f = cf.read("~/recipes/ggap.nc")[0]

# %%
# 3. Create the file with subplots. If changing the number of subplots,
# ensure the number of rows * number of columns = the number of projections.
# Here we are doing 6 projections so 2 x 3 is fine:
cfp.gopen(rows=2, columns=3, bottom=0.2, file="projections.png")

# %%
# 4. List the projection types to use. Here we are using
# Cylindrical/Default, North Pole Stereographic, South Pole Stereographic,
# Mollweide, Mercator and Robinson. However there are several other choices
# possible, see:
# https://ncas-cms.github.io/cf-plot/build/user_guide.html#appendixc. Our
# chosen list is:
projtypes = ["cyl", "npstere", "spstere", "moll", "merc", "robin"]

# %%
# 5. Loop through the list of projection types and plot each as a sub-plot:
for i, proj in enumerate(projtypes):
# gpos has 1 added to the index because it takes 1 as its first value
cfp.gpos(i + 1)
cfp.mapset(proj=proj)

# For the final plot only, add a colour bar to cover all the sub-plots
if i == len(projtypes) - 1:
cfp.con(
f.subspace(pressure=850),
lines=False,
title=proj,
colorbar_position=[0.1, 0.1, 0.8, 0.02],
colorbar_orientation="horizontal",
)
else:
cfp.con(
f.subspace(pressure=850),
lines=False,
title=proj,
colorbar=False,
)
cfp.gclose()
6 changes: 4 additions & 2 deletions docs/source/recipes/recipe_list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ plot_06_recipe.html#sphx-glr-recipes-plot-06-recipe-py
plot_07_recipe.html#sphx-glr-recipes-plot-07-recipe-py
<div class="sphx-glr-thumbcontainer aggregate lineplot subspace" tooltip="Aggregate, Lineplot, Subspace">
plot_08_recipe.html#sphx-glr-recipes-plot-08-recipe-py
<div class="sphx-glr-thumbcontainer collapse contourmap" tooltip="Collapse, Contourmap">
<div class="sphx-glr-thumbcontainer collapse contourmap" tooltip="Collapse, Contourmap, Subplot">
plot_09_recipe.html#sphx-glr-recipes-plot-09-recipe-py
<div class="sphx-glr-thumbcontainer histogram" tooltip="Histogram">
plot_10_recipe.html#sphx-glr-recipes-plot-10-recipe-py
Expand All @@ -27,4 +27,6 @@ plot_13_recipe.html#sphx-glr-recipes-plot-13-recipe-py
plot_14_recipe.html#sphx-glr-recipes-plot-14-recipe-py
<div class="sphx-glr-thumbcontainer subspace collapse contourmap" tooltip="Subspace, Collapse, Contourmap">
plot_15_recipe.html#sphx-glr-recipes-plot-15-recipe-py
<div class="sphx-glr-thumbcontainer histogram subspace" tooltip="Histogram, Subspace">
<div class="sphx-glr-thumbcontainer histogram subspace" tooltip="Histogram, Subspace, Subplot">
plot_16_recipe.html#sphx-glr-recipes-plot-16-recipe-py
<div class="sphx-glr-thumbcontainer contourmap subspace subplot" tooltip="Contourmap, Subspace, Subplot">

0 comments on commit ac9ce15

Please sign in to comment.