forked from GenericMappingTools/pygmt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a gallery example showing different colormaps in subplots (Generi…
…cMappingTools#1394) Co-authored-by: Will Schlitzer <[email protected]> Co-authored-by: Michael Grund <[email protected]> Co-authored-by: Wei Ji <[email protected]>
- Loading branch information
1 parent
470d00a
commit de8a089
Showing
1 changed file
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
""" | ||
Multiple colormaps | ||
------------------ | ||
This gallery example shows how to create multiple colormaps for different subplots. To | ||
better understand how GMT modern mode maintains several levels of colormaps, | ||
please refer to :gmt-docs:`cookbook/features.html#gmt-modern-mode-hierarchical-levels` | ||
for details. | ||
""" | ||
import pygmt | ||
|
||
fig = pygmt.Figure() | ||
|
||
# Load Earth relief data for the entire globe and a subset region | ||
grid_globe = pygmt.datasets.load_earth_relief(resolution="01d") | ||
subset_region = [-14, 30, 35, 60] | ||
grid_subset = pygmt.datasets.load_earth_relief(resolution="10m", region=subset_region) | ||
|
||
# Define a 1-row, 2-column subplot layout. The overall figure dimensions is set | ||
# to be 15 cm wide and 8 cm high. Each subplot is automatically labelled. | ||
# The space between the subplots is set to be 0.5 cm. | ||
with fig.subplot( | ||
nrows=1, ncols=2, figsize=("15c", "8c"), autolabel=True, margins="0.5c" | ||
): | ||
# Activate the first panel so that the colormap created by the makecpt | ||
# method is a panel-level CPT | ||
with fig.set_panel(panel=0): | ||
pygmt.makecpt(cmap="geo", series=[-8000, 8000]) | ||
# "R?" means Winkel Tripel projection with map width automatically | ||
# determined from the subplot width. | ||
fig.grdimage(grid=grid_globe, projection="R?", region="g", frame=True) | ||
fig.colorbar(frame=["a4000f2000", "x+lElevation", "y+lm"]) | ||
# Activate the second panel so that the colormap created by the makecpt | ||
# method is a panel-level CPT | ||
with fig.set_panel(panel=1): | ||
pygmt.makecpt(cmap="globe", series=[-6000, 3000]) | ||
# "M?" means Mercator projection with map width also automatically | ||
# determined from the subplot width. | ||
fig.grdimage( | ||
grid=grid_subset, projection="M?", region=subset_region, frame=True | ||
) | ||
fig.colorbar(frame=["a2000f1000", "x+lElevation", "y+lm"]) | ||
|
||
fig.show() |