-
Notifications
You must be signed in to change notification settings - Fork 245
Expand Colorbar gallery example for categorical data #2395
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 11 commits
ef9ecaf
35d8add
f54ee8e
1ce0870
a19d21c
f0f6e67
1429ade
3a70bf1
9f455ff
5ebcdb2
e409be5
1100260
29a7bb7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 figure frame using a 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 | ||
|
|
@@ -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", | ||
|
|
@@ -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 figure frame (J) at Middle Right (MR), | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In my opinion "figure" is not correct here, since the whole object is the figure, including the area outside the map frame where the colorbar is placed.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see your point. My intention to change it was that the generated figure is no geographical map. Maybe "plot" would serve as a more general term? But I am not sure whether there is a clear differentiation between "plot" and "figure". Thus, I changed it back to "map" in commit 29a7bb7. |
||
| # 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", | ||
|
|
@@ -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 figure 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() | ||
Uh oh!
There was an error while loading. Please reload this page.