|
2 | 2 | Colorbar
|
3 | 3 | --------
|
4 | 4 |
|
5 |
| -The :meth:`pygmt.Figure.colorbar` method creates a color scalebar. We must specify the |
6 |
| -colormap via the ``cmap`` argument, and set the placement via the ``position`` argument. |
7 |
| -The full list of color paletted tables can be found at :gmt-docs:`cookbook/cpts.html`. |
8 |
| -You can set the `position` of the colorbar using the following options: |
9 |
| -
|
10 |
| -- j/J: justified inside/outside the mapframe using any 2 character combination of |
11 |
| - vertical (**T** op, **M** iddle, **B** ottom) and horizontal (**L** eft, **C** enter, |
12 |
| - **R** ight) alignment codes, e.g. `position="jTR"` for top right. |
13 |
| -- g: using map coordinates, e.g. `position="g170/-45"` for longitude 170E, latitude 45S. |
14 |
| -- x: using paper coordinates, e.g. `position="x5c/7c"` for 5cm,7cm from anchor point. |
| 5 | +The :meth:`pygmt.Figure.colorbar` method creates a color scalebar. We must |
| 6 | +specify the colormap via the ``cmap`` argument, and optionally set the |
| 7 | +placement via the ``position`` argument. The full list of color palette tables |
| 8 | +can be found at :gmt-docs:`cookbook/cpts.html`. You can set the `position` of |
| 9 | +the colorbar using the following options: |
| 10 | +
|
| 11 | +- j/J: justified inside/outside the map frame using any 2 character combination |
| 12 | + of vertical (**T** op, **M** iddle, **B** ottom) and horizontal (**L** eft, |
| 13 | + **C** enter, **R** ight) alignment codes, e.g. `position="jTR"` for top |
| 14 | + right. |
| 15 | +- g: using map coordinates, e.g. `position="g170/-45"` for longitude 170E, |
| 16 | + latitude 45S. |
| 17 | +- x: using paper coordinates, e.g. `position="x5c/7c"` for 5cm,7cm from anchor |
| 18 | + point. |
15 | 19 | - n: using normalized (0-1) coordinates, e.g. `position="n0.4/0.8"`.
|
16 | 20 |
|
17 |
| -Note that the anchor point defaults to the bottom left (BL). Append +h to ``position`` |
18 |
| -to get a horizontal colorbar instead of a vertical one. For more advanced styling |
19 |
| -options, see the full option list at :gmt-docs:`colorbar.html`. |
| 21 | +Note that the anchor point defaults to the bottom left (BL). Append +h to |
| 22 | +``position`` to get a horizontal colorbar instead of a vertical one. For more |
| 23 | +advanced styling options, see the full option list at |
| 24 | +:gmt-docs:`colorbar.html`. |
20 | 25 | """
|
21 | 26 | import pygmt
|
22 | 27 |
|
23 | 28 | fig = pygmt.Figure()
|
24 |
| -fig.basemap(region=[0, 3, 6, 9], projection="t0/3c", frame=True) |
| 29 | +fig.basemap(region=[0, 3, 6, 9], projection="x3c", frame=["af", 'WSne+t"Colorbars"']) |
25 | 30 |
|
26 |
| -# Create a colorbar suitable for surface topography- oleron |
| 31 | +## Create a colorbar designed for seismic tomography - roma |
| 32 | +# Colorbar is placed at bottom center (BC) by default if no position is given |
| 33 | +fig.colorbar(cmap="roma", frame=["x+lVelocity", "y+lm/s"]) |
27 | 34 |
|
| 35 | +## Create a colorbar showing the scientific rainbow - batlow |
28 | 36 | fig.colorbar(
|
29 |
| - cmap="oleron", |
30 |
| - position="jTC+w6c/1c+h", # justified inside map frame (j) at Top Center (TC) |
31 |
| - box=True, |
32 |
| - frame=["+Loleron", "xaf", "y+lm"], |
33 |
| - scale=10, |
34 |
| -) |
35 |
| -# Create a colorbar designed for seismic tomography- roma |
36 |
| -fig.colorbar( |
37 |
| - cmap="roma", |
38 |
| - position="x1.2c/4.75c+w6c/1c+h", # plot using paper coordinates (x) at 1.2cm,4.75cm |
| 37 | + cmap="batlow", |
| 38 | + # Colorbar positioned at map coordinates (g) longitude/latitude 0.3/8.7, |
| 39 | + # with a length/width (+w) of 4cm by 0.5cm, and plotted horizontally (+h) |
| 40 | + position="g0.3/8.7+w4c/0.5c+h", |
39 | 41 | box=True,
|
40 |
| - frame=["+Lroma", "xaf", "y+lm/s"], |
41 |
| - scale=10, |
| 42 | + frame=["x+lTemperature", r"y+l\260C"], |
| 43 | + scale=100, |
42 | 44 | )
|
43 |
| -# Create a colorbar showing the scientific rainbow - batlow |
| 45 | + |
| 46 | +## Create a colorbar suitable for surface topography - oleron |
44 | 47 | fig.colorbar(
|
45 |
| - cmap="batlow", |
46 |
| - position="g0.45/6.6+w6c/1c+h", # plot using map coordinates (g) at lon/lat 0.45/6.6 |
47 |
| - box=True, |
48 |
| - frame=["+Lbatlow", "xaf", r"y+l\260C"], |
| 48 | + cmap="oleron", |
| 49 | + # Colorbar position justified outside map frame (J) at Middle Right (MR), |
| 50 | + # offset (+o) by 1cm horizontally and 0cm vertically from anchor point, |
| 51 | + # with a length/width (+w) of 7cm by 0.5cm and a box for NaN values (+n) |
| 52 | + position="JMR+o1c/0c+w7c/0.5c+n+mc", |
| 53 | + # Note that the label 'Elevation' is moved to the opposite side and plotted |
| 54 | + # vertically as a column of text using '+mc' in the position argument above |
| 55 | + frame=["x+lElevation", "y+lm"], |
49 | 56 | scale=10,
|
50 | 57 | )
|
51 | 58 |
|
|
0 commit comments