|
8 | 8 | can be found at :gmt-docs:`cookbook/cpts.html`. You can set the ``position`` of
|
9 | 9 | the colorbar using the following options:
|
10 | 10 |
|
11 |
| -- **j/J**: justified inside/outside the map frame using any 2-character |
| 11 | +- **j/J**: placed inside/outside the map frame using any 2-character |
12 | 12 | combination of vertical (**T**\ op, **M**\ iddle, **B**\ ottom) and
|
13 | 13 | horizontal (**L**\ eft, **C**\ enter, **R**\ ight) alignment codes, e.g.
|
14 |
| - ``position="jTR"`` for top right. |
| 14 | + ``position="jTR"`` for Top Right. |
15 | 15 | - **g**: using map coordinates, e.g. ``position="g170/-45"`` for longitude
|
16 | 16 | 170E, latitude 45S.
|
17 | 17 | - **x**: using paper coordinates, e.g. ``position="x5c/7c"`` for 5 cm, 7 cm
|
|
21 | 21 | Note that the anchor point defaults to the bottom left (**BL**). Append ``+h``
|
22 | 22 | to ``position`` to get a horizontal colorbar instead of a vertical one.
|
23 | 23 | """
|
| 24 | + |
24 | 25 | import pygmt
|
25 | 26 |
|
26 | 27 | fig = pygmt.Figure()
|
27 | 28 | fig.basemap(region=[0, 3, 6, 9], projection="x3c", frame=["af", "WSne+tColorbars"])
|
28 | 29 |
|
| 30 | +# ============ |
29 | 31 | # Create a colorbar designed for seismic tomography - roma
|
30 | 32 | # Colorbar is placed at bottom center (BC) by default if no position is given
|
31 | 33 | fig.colorbar(cmap="roma", frame=["x+lVelocity", "y+lm/s"])
|
32 | 34 |
|
| 35 | +# ============ |
33 | 36 | # Create a colorbar showing the scientific rainbow - batlow
|
34 | 37 | fig.colorbar(
|
35 | 38 | cmap="batlow",
|
|
41 | 44 | scale=100,
|
42 | 45 | )
|
43 | 46 |
|
| 47 | +# ============ |
44 | 48 | # Create a colorbar suitable for surface topography - oleron
|
45 | 49 | fig.colorbar(
|
46 | 50 | cmap="oleron",
|
47 |
| - # Colorbar position justified outside map frame (J) at Middle Right (MR), |
| 51 | + # Colorbar placed outside map frame (J) at Middle Right (MR), |
48 | 52 | # offset (+o) by 1 cm horizontally and 0 cm vertically from anchor point,
|
49 | 53 | # with a length/width (+w) of 7 cm by 0.5 cm and a box for NaN values (+n)
|
50 | 54 | position="JMR+o1c/0c+w7c/0.5c+n+mc",
|
|
55 | 59 | scale=10,
|
56 | 60 | )
|
57 | 61 |
|
| 62 | +# ============ |
| 63 | +# Create a colorbar suitable for categorical data - hawaii |
| 64 | +# Set up the colormap |
| 65 | +pygmt.makecpt( |
| 66 | + cmap="hawaii", |
| 67 | + series=[0, 3, 1], |
| 68 | + # Comma-separated string for the annotations of the colorbar |
| 69 | + color_model="+cA,B,C,D", |
| 70 | +) |
| 71 | +# Plot the colorbar |
| 72 | +fig.colorbar( |
| 73 | + cmap=True, # Use colormap set up above |
| 74 | + # Colorbar placed inside map frame (j) at Bottom Left (BL), |
| 75 | + # offset (+o) by 0.5 cm horizontally and 0.8 cm vertically from anchor |
| 76 | + # point, and plotted horizontally (+h) |
| 77 | + position="jBL+o0.5c/0.8c+h", |
| 78 | + box=True, |
| 79 | + # Divide colorbar into equal-sized rectangles |
| 80 | + equalsize=0.5, |
| 81 | +) |
| 82 | + |
58 | 83 | fig.show()
|
0 commit comments