-
Notifications
You must be signed in to change notification settings - Fork 235
Wrap colorbar #332
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
Merged
Merged
Wrap colorbar #332
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
9947a96
Wrap colorbar
weiji14 1e14c33
Alias box (F) for colorbar
weiji14 cbca922
Alias truncate (G) for colorbar
weiji14 fac8866
Alias scale (W) for colorbar
weiji14 4d74d0f
Merge branch 'master' into mapping/colorbar
weiji14 f4adb84
Merge branch 'master' into mapping/colorbar
weiji14 0455990
Gallery example for colorbar
weiji14 8a8562d
Merge branch 'master' into mapping/colorbar
weiji14 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
| @@ -1,2 +1,2 @@ | ||
| Lines, points, and scatters | ||
| --------------------------- | ||
| Plotting map items | ||
| ------------------ |
This file contains hidden or 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,52 @@ | ||
| """ | ||
| Colorbar | ||
| -------- | ||
|
|
||
| The :meth:`pygmt.Figure.colorbar` method creates a color scalebar. We must specify the | ||
| colormap via the ``cmap`` argument, and set the placement via the ``position`` argument. | ||
| The full list of color paletted tables 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 mapframe 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. | ||
| - g: using map coordinates, e.g. `position="g170/-45"` for longitude 170E, latitude 45S. | ||
| - x: using paper coordinates, e.g. `position="x5c/7c"` for 5cm,7cm from anchor point. | ||
| - n: using normalized (0-1) coordinates, e.g. `position="n0.4/0.8"`. | ||
|
|
||
| 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. For more advanced styling | ||
| options, see the full option list at :gmt-docs:`colorbar.html`. | ||
| """ | ||
| import pygmt | ||
|
|
||
| fig = pygmt.Figure() | ||
| fig.basemap(region=[0, 3, 6, 9], projection="t0/3c", frame=True) | ||
|
|
||
| # Create a colorbar suitable for surface topography- oleron | ||
|
|
||
| fig.colorbar( | ||
| cmap="oleron", | ||
| position="jTC+w6c/1c+h", # justified inside map frame (j) at Top Center (TC) | ||
| box=True, | ||
| frame=["+Loleron", "xaf", "y+lm"], | ||
| scale=10, | ||
| ) | ||
| # Create a colorbar designed for seismic tomography- roma | ||
| fig.colorbar( | ||
| cmap="roma", | ||
| position="x1.2c/4.75c+w6c/1c+h", # plot using paper coordinates (x) at 1.2cm,4.75cm | ||
| box=True, | ||
| frame=["+Lroma", "xaf", "y+lm/s"], | ||
| scale=10, | ||
| ) | ||
| # Create a colorbar showing the scientific rainbow - batlow | ||
| fig.colorbar( | ||
| cmap="batlow", | ||
| position="g0.45/6.6+w6c/1c+h", # plot using map coordinates (g) at lon/lat 0.45/6.6 | ||
| box=True, | ||
| frame=["+Lbatlow", "xaf", r"y+l\260C"], | ||
| scale=10, | ||
| ) | ||
|
|
||
| fig.show() | ||
This file contains hidden or 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+17.7 KB
pygmt/tests/baseline/test_colorbar_positioned_using_justification_code.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+18.7 KB
pygmt/tests/baseline/test_colorbar_positioned_using_map_coordinates.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+18.5 KB
pygmt/tests/baseline/test_colorbar_positioned_using_normalized_coords.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+989 Bytes
pygmt/tests/baseline/test_colorbar_using_paper_coordinates_horizontal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or 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,150 @@ | ||
| """ | ||
| Tests colorbar | ||
| """ | ||
| import pytest | ||
|
|
||
| from .. import Figure | ||
|
|
||
|
|
||
| @pytest.mark.mpl_image_compare | ||
| def test_colorbar_using_paper_coordinates(): | ||
| """ | ||
| Create colorbar positioned at 0cm,0cm with length 1cm and width 0.5cm. | ||
| """ | ||
| fig = Figure() | ||
| fig.colorbar(cmap="rainbow", position="x0c/0c+w1c/0.5c") | ||
| return fig | ||
|
|
||
|
|
||
| @pytest.mark.mpl_image_compare | ||
| def test_colorbar_using_paper_coordinates_horizontal(): | ||
| """ | ||
| Create colorbar positioned at 0cm,0cm with length 2cm oriented horizontally. | ||
| """ | ||
| fig = Figure() | ||
| fig.colorbar(cmap="rainbow", position="x0c/0c+w2c+h") | ||
| return fig | ||
|
|
||
|
|
||
| @pytest.mark.mpl_image_compare | ||
| def test_colorbar_positioned_using_map_coordinates(): | ||
| """ | ||
| Create colorbar positioned at longitude,latitude 3,6 with length 2cm. | ||
| """ | ||
| fig = Figure() | ||
| fig.basemap(region=[2, 4, 6, 8], projection="t0/2c", frame=True) | ||
| fig.colorbar(cmap="rainbow", position="g3/6+w2c") | ||
| return fig | ||
|
|
||
|
|
||
| @pytest.mark.mpl_image_compare | ||
| def test_colorbar_positioned_using_justification_code(): | ||
| """ | ||
| Create colorbar positioned at Top Center inside the map frame with length 2cm. | ||
| """ | ||
| fig = Figure() | ||
| fig.basemap(region=[2, 4, 6, 8], projection="t0/2c", frame=True) | ||
| fig.colorbar(cmap="rainbow", position="jTC+w2c") | ||
| return fig | ||
|
|
||
|
|
||
| @pytest.mark.mpl_image_compare | ||
| def test_colorbar_positioned_using_normalized_coords(): | ||
| """ | ||
| Create colorbar positioned at normalized coordinates 0.75,0.25 with length 2cm. | ||
| """ | ||
| fig = Figure() | ||
| fig.basemap(region=[2, 4, 6, 8], projection="t0/2c", frame=True) | ||
| fig.colorbar(cmap="rainbow", position="n0.75/0.25+w2c") | ||
| return fig | ||
|
|
||
|
|
||
| @pytest.mark.mpl_image_compare | ||
| def test_colorbar_box(): | ||
| """ | ||
| Create colorbar with box around it. | ||
| """ | ||
| fig = Figure() | ||
| fig.colorbar(cmap="rainbow", box=True, position="x0c/0c+w1c/0.5c") | ||
| return fig | ||
|
|
||
|
|
||
| @pytest.mark.mpl_image_compare | ||
| def test_colorbar_box_with_pen(): | ||
| """ | ||
| Create colorbar with box that has a different colored pen. | ||
| """ | ||
| fig = Figure() | ||
| fig.colorbar(cmap="rainbow", box="+porange", position="x0c/0c+w1c/0.5c") | ||
| return fig | ||
|
|
||
|
|
||
| @pytest.mark.mpl_image_compare | ||
| def test_colorbar_box_with_fill(): | ||
| """ | ||
| Create colorbar with box that has a different colored fill. | ||
| """ | ||
| fig = Figure() | ||
| fig.colorbar(cmap="rainbow", box="+gorange", position="x0c/0c+w1c/0.5c") | ||
| return fig | ||
|
|
||
|
|
||
| @pytest.mark.mpl_image_compare | ||
| def test_colorbar_box_with_clearance(): | ||
| """ | ||
| Create colorbar with box that has an x-clearance of 0.8cm and y-clearance of 0.4cm. | ||
| """ | ||
| fig = Figure() | ||
| fig.colorbar(cmap="rainbow", box="+c0.8c/0.4c+porange", position="x0c/0c+w1c/0.5c") | ||
| return fig | ||
|
|
||
|
|
||
| @pytest.mark.mpl_image_compare | ||
| def test_colorbar_box_with_secondary_border(): | ||
| """ | ||
| Create colorbar with box that has a secondary, inner border in addition to the main | ||
| primary, outer border. | ||
| """ | ||
| fig = Figure() | ||
| fig.colorbar(cmap="rainbow", box="+porange+imagenta", position="x0c/0c+w1c/0.5c") | ||
| return fig | ||
|
|
||
|
|
||
| @pytest.mark.mpl_image_compare | ||
| def test_colorbar_box_with_rounded_corners(): | ||
| """ | ||
| Create colorbar with box that has rounded corners. | ||
| """ | ||
| fig = Figure() | ||
| fig.colorbar(cmap="rainbow", box="+porange+r", position="x0c/0c+w1c/0.5c") | ||
| return fig | ||
|
|
||
|
|
||
| @pytest.mark.mpl_image_compare | ||
| def test_colorbar_box_with_offset_background(): | ||
| """ | ||
| Create colorbar with box and an offset background shaded region. | ||
| """ | ||
| fig = Figure() | ||
| fig.colorbar(cmap="rainbow", box="+s5p/-5p", position="x0c/0c+w1c/0.5c") | ||
| return fig | ||
|
|
||
|
|
||
| @pytest.mark.mpl_image_compare | ||
| def test_colorbar_truncated_to_zlow_zhigh(): | ||
| """ | ||
| Create colorbar truncated to z-low and z-high. | ||
| """ | ||
| fig = Figure() | ||
| fig.colorbar(cmap="rainbow", truncate=[0.15, 0.85], position="x0c/0c+w2c/0.5c") | ||
| return fig | ||
|
|
||
|
|
||
| @pytest.mark.mpl_image_compare | ||
| def test_colorbar_scaled_z_values(): | ||
| """ | ||
| Create colorbar with z-values scaled to 0.1x of the original CPT. | ||
| """ | ||
| fig = Figure() | ||
| fig.colorbar(cmap="rainbow", scale=0.1, position="x0c/0c+w2c/0.5c") | ||
| return fig |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have we documented how the argument
is equivalent to
(i.e. use a list to replicate repeated flags) somewhere? I think it could be a good item to add to the Note for experienced GMT users in the docs and can do so if desired.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Funny you said that, I only discovered that recently too at #325 (comment) but didn't know where best to put it in the docs.
Yep, go for it!