diff --git a/docs/source/recipes/plot_16_recipe.py b/docs/source/recipes/plot_16_recipe.py new file mode 100644 index 0000000000..c0d0d76a22 --- /dev/null +++ b/docs/source/recipes/plot_16_recipe.py @@ -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() diff --git a/docs/source/recipes/recipe_list.txt b/docs/source/recipes/recipe_list.txt index f39297f9cb..51d038845d 100644 --- a/docs/source/recipes/recipe_list.txt +++ b/docs/source/recipes/recipe_list.txt @@ -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
plot_08_recipe.html#sphx-glr-recipes-plot-08-recipe-py -
+
plot_09_recipe.html#sphx-glr-recipes-plot-09-recipe-py
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 plot_14_recipe.html#sphx-glr-recipes-plot-14-recipe-py
plot_15_recipe.html#sphx-glr-recipes-plot-15-recipe-py -
\ No newline at end of file +
+plot_16_recipe.html#sphx-glr-recipes-plot-16-recipe-py +