Skip to content

Commit

Permalink
Expand Colorbar gallery example for categorical data (#2395)
Browse files Browse the repository at this point in the history
Co-authored-by: Michael Grund <[email protected]>
  • Loading branch information
yvonnefroehlich and michaelgrund authored Mar 11, 2023
1 parent 5364749 commit 8540a9d
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions examples/gallery/embellishments/colorbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
can be found at :gmt-docs:`cookbook/cpts.html`. You can set the ``position`` of
the colorbar using the following options:
- **j/J**: justified inside/outside the map frame using any 2-character
- **j/J**: placed inside/outside the map frame using any 2-character
combination of vertical (**T**\ op, **M**\ iddle, **B**\ ottom) and
horizontal (**L**\ eft, **C**\ enter, **R**\ ight) alignment codes, e.g.
``position="jTR"`` for top right.
``position="jTR"`` for Top Right.
- **g**: using map coordinates, e.g. ``position="g170/-45"`` for longitude
170E, latitude 45S.
- **x**: using paper coordinates, e.g. ``position="x5c/7c"`` for 5 cm, 7 cm
Expand All @@ -21,15 +21,18 @@
Note that the anchor point defaults to the bottom left (**BL**). Append ``+h``
to ``position`` to get a horizontal colorbar instead of a vertical one.
"""

import pygmt

fig = pygmt.Figure()
fig.basemap(region=[0, 3, 6, 9], projection="x3c", frame=["af", "WSne+tColorbars"])

# ============
# Create a colorbar designed for seismic tomography - roma
# Colorbar is placed at bottom center (BC) by default if no position is given
fig.colorbar(cmap="roma", frame=["x+lVelocity", "y+lm/s"])

# ============
# Create a colorbar showing the scientific rainbow - batlow
fig.colorbar(
cmap="batlow",
Expand All @@ -41,10 +44,11 @@
scale=100,
)

# ============
# Create a colorbar suitable for surface topography - oleron
fig.colorbar(
cmap="oleron",
# Colorbar position justified outside map frame (J) at Middle Right (MR),
# Colorbar placed outside map frame (J) at Middle Right (MR),
# offset (+o) by 1 cm horizontally and 0 cm vertically from anchor point,
# with a length/width (+w) of 7 cm by 0.5 cm and a box for NaN values (+n)
position="JMR+o1c/0c+w7c/0.5c+n+mc",
Expand All @@ -55,4 +59,25 @@
scale=10,
)

# ============
# Create a colorbar suitable for categorical data - hawaii
# Set up the colormap
pygmt.makecpt(
cmap="hawaii",
series=[0, 3, 1],
# Comma-separated string for the annotations of the colorbar
color_model="+cA,B,C,D",
)
# Plot the colorbar
fig.colorbar(
cmap=True, # Use colormap set up above
# Colorbar placed inside map frame (j) at Bottom Left (BL),
# offset (+o) by 0.5 cm horizontally and 0.8 cm vertically from anchor
# point, and plotted horizontally (+h)
position="jBL+o0.5c/0.8c+h",
box=True,
# Divide colorbar into equal-sized rectangles
equalsize=0.5,
)

fig.show()

0 comments on commit 8540a9d

Please sign in to comment.