5. Create subplots#

There are two different ways to create subplots in PolarToolkit, which we demonstrate here.

Import the modules

[2]:
%load_ext autoreload
%autoreload 2
import os

from polartoolkit import fetch, maps, regions
[3]:
# set default to southern hemisphere for this notebook
os.environ["POLARTOOLKIT_HEMISPHERE"] = "south"

Define the region of interest and fetch the datasets

[4]:
# choose a geographic region to extract data for
region = regions.getz_ice_shelf

grid1 = fetch.bedmap2(layer="bed", region=region)
grid2 = fetch.gravity(
    version="antgg-2021", anomaly_type="FA", region=region
).free_air_anomaly
grid3 = fetch.magnetics(version="admap2", region=region)
grid4 = fetch.ice_vel(
    region=region,
)
grdcut [WARNING]: (w - x_min) must equal (NX + eps) * x_inc), where NX is an integer and |eps| <= 0.0001.
grdcut [WARNING]: w reset from -1624000 to -1625000
grdcut [WARNING]: (s - y_min) must equal (NY + eps) * y_inc), where NY is an integer and |eps| <= 0.0001.
grdcut [WARNING]: s reset from -1234000 to -1235000
grdcut [WARNING]: (n - y_min) must equal (NY + eps) * y_inc), where NY is an integer and |eps| <= 0.0001.
grdcut [WARNING]: n reset from -664000 to -660000
grdcut [WARNING]: (w - x_min) must equal (NX + eps) * x_inc), where NX is an integer and |eps| <= 0.0001.
grdcut [WARNING]: w reset from -1624000 to -1625000
grdcut [WARNING]: (s - y_min) must equal (NY + eps) * y_inc), where NY is an integer and |eps| <= 0.0001.
grdcut [WARNING]: s reset from -1234000 to -1235000
grdcut [WARNING]: (n - y_min) must equal (NY + eps) * y_inc), where NY is an integer and |eps| <= 0.0001.
grdcut [WARNING]: n reset from -664000 to -660000
grdcut [WARNING]: (w - x_min) must equal (NX + eps) * x_inc), where NX is an integer and |eps| <= 0.0001.
grdcut [WARNING]: w reset from -1624000 to -1625000
grdcut [WARNING]: (s - y_min) must equal (NY + eps) * y_inc), where NY is an integer and |eps| <= 0.0001.
grdcut [WARNING]: s reset from -1234000 to -1235000
grdcut [WARNING]: (n - y_min) must equal (NY + eps) * y_inc), where NY is an integer and |eps| <= 0.0001.
grdcut [WARNING]: n reset from -664000 to -660000
grdcut [WARNING]: (w - x_min) must equal (NX + eps) * x_inc), where NX is an integer and |eps| <= 0.0001.
grdcut [WARNING]: w reset from -1624000 to -1625000
grdcut [WARNING]: (s - y_min) must equal (NY + eps) * y_inc), where NY is an integer and |eps| <= 0.0001.
grdcut [WARNING]: s reset from -1234000 to -1235000
grdcut [WARNING]: (n - y_min) must equal (NY + eps) * y_inc), where NY is an integer and |eps| <= 0.0001.
grdcut [WARNING]: n reset from -664000 to -660000
grdcut [WARNING]: (w - x_min) must equal (NX + eps) * x_inc), where NX is an integer and |eps| <= 0.0001.
grdcut [WARNING]: w reset from -1624000 to -1624500
grdcut [WARNING]: (e - x_min) must equal (NX + eps) * x_inc), where NX is an integer and |eps| <= 0.0001.
grdcut [WARNING]: e reset from -1130000 to -1129500
grdcut [WARNING]: (s - y_min) must equal (NY + eps) * y_inc), where NY is an integer and |eps| <= 0.0001.
grdcut [WARNING]: s reset from -1234000 to -1234500
grdcut [WARNING]: (n - y_min) must equal (NY + eps) * y_inc), where NY is an integer and |eps| <= 0.0001.
grdcut [WARNING]: n reset from -664000 to -663000
grdcut [WARNING]: (w - x_min) must equal (NX + eps) * x_inc), where NX is an integer and |eps| <= 0.0001.
grdcut [WARNING]: w reset from -1624000 to -1624500
grdcut [WARNING]: (e - x_min) must equal (NX + eps) * x_inc), where NX is an integer and |eps| <= 0.0001.
grdcut [WARNING]: e reset from -1130000 to -1129500
grdcut [WARNING]: (s - y_min) must equal (NY + eps) * y_inc), where NY is an integer and |eps| <= 0.0001.
grdcut [WARNING]: s reset from -1234000 to -1234500
grdcut [WARNING]: (n - y_min) must equal (NY + eps) * y_inc), where NY is an integer and |eps| <= 0.0001.
grdcut [WARNING]: n reset from -664000 to -663000
grdcut [WARNING]: (w - x_min) must equal (NX + eps) * x_inc), where NX is an integer and |eps| <= 0.0001.
grdcut [WARNING]: w reset from -1624000 to -1625000
grdcut [WARNING]: (s - y_min) must equal (NY + eps) * y_inc), where NY is an integer and |eps| <= 0.0001.
grdcut [WARNING]: s reset from -1234000 to -1235000
grdcut [WARNING]: (n - y_min) must equal (NY + eps) * y_inc), where NY is an integer and |eps| <= 0.0001.
grdcut [WARNING]: n reset from -664000 to -660000
grdcut [WARNING]: (w - x_min) must equal (NX + eps) * x_inc), where NX is an integer and |eps| <= 0.0001.
grdcut [WARNING]: w reset from -1624000 to -1625000
grdcut [WARNING]: (s - y_min) must equal (NY + eps) * y_inc), where NY is an integer and |eps| <= 0.0001.
grdcut [WARNING]: s reset from -1234000 to -1235000
grdcut [WARNING]: (n - y_min) must equal (NY + eps) * y_inc), where NY is an integer and |eps| <= 0.0001.
grdcut [WARNING]: n reset from -664000 to -660000

5.1. Method 1: maps.subplots()#

This functions takes a list of grids and plots each of them. You can customize the number of rows and columns by passing a tuple of (number rows, number columns) to dims. All the arguments are passed to maps.plot_grd() to enable customing each plot. You can also customize each plot individually by passing lists of parameter values (1 for each subplot) to the following arguments: titles, cmaps, cbar_labels, and cbar_units.

[5]:
fig = maps.subplots(
    [grid1, grid2, grid3, grid4],
    # dims=(2,1), # 1 row, 2 columns, if you want to change from the default
    fig_title="Making a subplot",
    titles=[
        "Bedmap2 Bedrock Elevation",
        "AntGG Free-Air Gravity Anomaly",
        "ADMAP2 Magnetic Anomaly",
        "Ice Velocity",
    ],
    cbar_labels=["m", "mGal", "nT", "m/yr"],
    coast=True,
    cmaps=["batlowW", "balance+h0", "balance+h0", "magma"],
    hist=True,
)

fig.show(dpi=200)
../_images/tutorial_05_subplots_7_0.png

5.2. Method 2: origin_shift#

For more control over customizing each subplot, or changing the layout of the subplots, you can use the argument origin_shift to setup your subplots.

[6]:
# create the first figure
fig = maps.plot_grd(
    grid1,
    cmap="batlowW",
    coast=True,
    title="Bedmap2 bed elevation",
    cbar_label="m",
    hist=True,
    inset=True,
)

# display the figure
fig.show(dpi=200)
../_images/tutorial_05_subplots_9_0.png

Add the second figure by passing the fig variable to plot_grd, and specifying origin_shift.

[7]:
fig = maps.plot_grd(
    grid2,
    fig=fig,
    origin_shift="x",  # shift subplot in horizontal direction
    # yshift_amount=1,  # default is 1, (1 figure width right)
    cmap="balance+h0",
    coast=True,
    title="Free-air gravity",
    cbar_label="mGal",
    hist=True,
)

# display the figure
fig.show(dpi=200)
../_images/tutorial_05_subplots_11_0.png
[8]:
fig = maps.plot_grd(
    grid3,
    fig=fig,
    origin_shift="both",  # shift subplot both down and to the left
    yshift_amount=-1,  # default is -1, (1 figure height down)
    xshift_amount=-1,
    cmap="balance+h0",
    coast=True,
    title="ADMAP2 magnetic anomaly",
    cbar_label="nT",
    hist=True,
)

# display the figure
fig.show(dpi=200)
../_images/tutorial_05_subplots_12_0.png
[9]:
fig = maps.plot_grd(
    grid4,
    fig=fig,
    origin_shift="x",  # shift subplot left
    cmap="magma",
    coast=True,
    title="Ice velocity",
    cbar_label="m/yr",
    hist=True,
)

# display the figure
fig.show(dpi=200)
../_images/tutorial_05_subplots_13_0.png

This also works with maps.basemap to create a subplot without a grid file.

[10]:
fig = maps.basemap(
    fig=fig,
    region=region,
    imagery_basemap=True,
    origin_shift="both",  # shift in both x and y directions
    yshift_amount=0.5,  # shift up by half a figure height
    xshift_amount=1,  # shift right by one figure width
    coast=True,
    points=fetch.bedmap_points(version="bedmap1", region=region),
    points_fill="cyan",
)

# display the figure
fig.show(dpi=200)
grdimage [WARNING]: (w - x_min) must equal (NX + eps) * x_inc), where NX is an integer and |eps| <= 0.0001.
grdimage [WARNING]: w reset from -1624000 to -1624229.29918
grdimage [WARNING]: (e - x_min) must equal (NX + eps) * x_inc), where NX is an integer and |eps| <= 0.0001.
grdimage [WARNING]: e reset from -1130000 to -1129807.66209
grdimage [WARNING]: (s - y_min) must equal (NY + eps) * y_inc), where NY is an integer and |eps| <= 0.0001.
grdimage [WARNING]: s reset from -1234000 to -1234065.03774
grdimage [WARNING]: (n - y_min) must equal (NY + eps) * y_inc), where NY is an integer and |eps| <= 0.0001.
grdimage [WARNING]: n reset from -664000 to -663825.03652
../_images/tutorial_05_subplots_15_1.png