|
| 1 | +""" |
| 2 | +Multiple colormaps |
| 3 | +------------------ |
| 4 | +This gallery example shows how to create multiple colormaps for different subplots. To |
| 5 | +better understand how GMT modern mode maintains several levels of colormaps, |
| 6 | +please refer to :gmt-docs:`cookbook/features.html#gmt-modern-mode-hierarchical-levels` |
| 7 | +for details. |
| 8 | +""" |
| 9 | +import pygmt |
| 10 | + |
| 11 | +fig = pygmt.Figure() |
| 12 | + |
| 13 | +# Load Earth relief data for the entire globe and a subset region |
| 14 | +grid_globe = pygmt.datasets.load_earth_relief(resolution="01d") |
| 15 | +subset_region = [-14, 30, 35, 60] |
| 16 | +grid_subset = pygmt.datasets.load_earth_relief(resolution="10m", region=subset_region) |
| 17 | + |
| 18 | +# Define a 1-row, 2-column subplot layout. The overall figure dimensions is set |
| 19 | +# to be 15 cm wide and 8 cm high. Each subplot is automatically labelled. |
| 20 | +# The space between the subplots is set to be 0.5 cm. |
| 21 | +with fig.subplot( |
| 22 | + nrows=1, ncols=2, figsize=("15c", "8c"), autolabel=True, margins="0.5c" |
| 23 | +): |
| 24 | + # Activate the first panel so that the colormap created by the makecpt |
| 25 | + # method is a panel-level CPT |
| 26 | + with fig.set_panel(panel=0): |
| 27 | + pygmt.makecpt(cmap="geo", series=[-8000, 8000]) |
| 28 | + # "R?" means Winkel Tripel projection with map width automatically |
| 29 | + # determined from the subplot width. |
| 30 | + fig.grdimage(grid=grid_globe, projection="R?", region="g", frame=True) |
| 31 | + fig.colorbar(frame=["a4000f2000", "x+lElevation", "y+lm"]) |
| 32 | + # Activate the second panel so that the colormap created by the makecpt |
| 33 | + # method is a panel-level CPT |
| 34 | + with fig.set_panel(panel=1): |
| 35 | + pygmt.makecpt(cmap="globe", series=[-6000, 3000]) |
| 36 | + # "M?" means Mercator projection with map width also automatically |
| 37 | + # determined from the subplot width. |
| 38 | + fig.grdimage( |
| 39 | + grid=grid_subset, projection="M?", region=subset_region, frame=True |
| 40 | + ) |
| 41 | + fig.colorbar(frame=["a2000f1000", "x+lElevation", "y+lm"]) |
| 42 | + |
| 43 | +fig.show() |
0 commit comments