-
Notifications
You must be signed in to change notification settings - Fork 228
Add a gallery example showing the usage of Figure.hlines and Figure.vlines #3755
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
Changes from 34 commits
Commits
Show all changes
44 commits
Select commit
Hold shift + click to select a range
6b9d64b
Create hlines_vlines.py
michaelgrund c3c3dcf
Update hlines_vlines.py
michaelgrund 5c2ea76
[format-command] fixes
actions-bot ddc8c06
add fig.show
michaelgrund 49f777f
update text
michaelgrund e41387f
add descriptions
michaelgrund 0354586
add texts
michaelgrund b3d5970
update texts
michaelgrund 6fd69f3
add texts
michaelgrund edbf3f6
[format-command] fixes
actions-bot 66f05ff
fix lengths
michaelgrund fbeb177
make consistent
michaelgrund 9cfe59e
Update hlines_vlines.py
michaelgrund b07b990
fix typo
michaelgrund 26f94ac
add x and y
michaelgrund b5be723
fix typos
michaelgrund c29ae86
Update hlines_vlines.py
michaelgrund b7e5d21
[format-command] fixes
actions-bot 49631b9
Merge branch 'main' into gallery-hlines-vlines
michaelgrund 51e386e
Merge branch 'main' into gallery-hlines-vlines
michaelgrund 8805817
Update hlines_vlines.py
michaelgrund f89cae5
rm trailing ws
michaelgrund 8ce2a18
fix typo
michaelgrund d863b9c
Update hlines.py
michaelgrund d686ac8
Update vlines.py
michaelgrund c8cfa36
Apply suggestions from code review
michaelgrund 5cee1a3
Update hlines_vlines.py
michaelgrund 74f3b70
Apply suggestions from code review
michaelgrund d9bf2e3
Merge branch 'main' into gallery-hlines-vlines
michaelgrund 43b3a68
adjust text
michaelgrund 80526c5
Update hlines_vlines.py
michaelgrund a98789b
Apply suggestions from code review
michaelgrund abfa638
shorten descriptions
michaelgrund 82d57f3
Update hlines_vlines.py
michaelgrund e1d7452
Apply suggestions from code review
michaelgrund aa20fa4
Merge branch 'main' into gallery-hlines-vlines
michaelgrund d1e7ff0
Update hlines_vlines.py
michaelgrund 7f64d32
Apply suggestions from code review
michaelgrund 0717bf7
Merge branch 'main' into gallery-hlines-vlines
michaelgrund 8b020ce
Apply suggestions from code review
michaelgrund 190e885
Merge branch 'main' into gallery-hlines-vlines
michaelgrund 63063a8
Apply suggestions from code review
michaelgrund 373e0a1
Apply suggestions from code review
michaelgrund 4040925
Merge branch 'main' into gallery-hlines-vlines
michaelgrund 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
""" | ||
Horizontal and vertical lines | ||
============================= | ||
|
||
The :meth:`pygmt.Figure.hlines` and :meth:`pygmt.Figure.vlines` methods allow to plot | ||
horizontal and vertical lines in Cartesian, geographic and polar coordinate systems. | ||
""" | ||
|
||
# %% | ||
# Cartesian coordinate system | ||
# --------------------------- | ||
# In Cartesian coordinate systems lines are plotted as straight lines. | ||
|
||
import pygmt | ||
|
||
fig = pygmt.Figure() | ||
|
||
fig.basemap( | ||
region=[0, 10, 0, 10], projection="X10c/10c", frame=["+thlines Cartesian", "af"] | ||
michaelgrund marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) | ||
|
||
# Add a horizontal line at y=9 | ||
fig.hlines(y=9, pen="1.5p,red3", label="Line 1") | ||
# Add a horizontal line at y=8 with x from 2 to 8 | ||
fig.hlines(y=8, xmin=2, xmax=8, pen="1.5p,gray30,-", label="Line 2") | ||
# Add two horizontal lines at y=6 and y=7 both with x from 3 to 7 | ||
fig.hlines(y=[6, 7], xmin=3, xmax=7, pen="1.5p,salmon", label="Lines 3 & 4") | ||
# Add two horizontal lines at y=4 and y=5 both with x from 4 to 9 | ||
fig.hlines(y=[4, 5], xmin=4, xmax=9, pen="1.5p,black,.", label="Lines 5 & 6") | ||
# Add two horizontal lines at y=2 and y=3 with different x limits | ||
fig.hlines( | ||
y=[2, 3], xmin=[0, 1], xmax=[7, 7.5], pen="1.5p,dodgerblue3", label="Lines 7 & 8" | ||
) | ||
fig.legend(position="JBR+jBR+o0.2c", box="+gwhite+p1p") | ||
|
||
fig.shift_origin(xshift="w+2c") | ||
|
||
fig.basemap( | ||
region=[0, 10, 0, 10], projection="X10c/10c", frame=["+tvlines Cartesian", "af"] | ||
) | ||
# Add a vertical line at x=1 | ||
fig.vlines(x=1, pen="1.5p,red3", label="Line 1") | ||
# Add a vertical line at x=2 with y from 2 to 8 | ||
fig.vlines(x=2, ymin=2, ymax=8, pen="1.5p,gray30,-", label="Line 2") | ||
# Add two vertical lines at x=3 and x=4 both with y from 3 to 7 | ||
fig.vlines(x=[3, 4], ymin=3, ymax=7, pen="1.5p,salmon", label="Lines 3 & 4") | ||
# Add two vertical lines at x=5 and x=6 both with y from 4 to 9 | ||
fig.vlines(x=[5, 6], ymin=4, ymax=9, pen="1.5p,black,.", label="Lines 5 & 6") | ||
# Add two vertical lines at x=7 and x=8 with different y limits | ||
fig.vlines( | ||
x=[7, 8], ymin=[0, 1], ymax=[7, 7.5], pen="1.5p,dodgerblue3", label="Lines 7 & 8" | ||
) | ||
fig.legend() | ||
|
||
fig.show() | ||
|
||
# %% | ||
# Geographic coordinate system | ||
# ---------------------------- | ||
# The same can be done in geographic coordinate systems where "horizontal" means lines | ||
# are plotted along parallels (constant latitude) while "vertical" means lines are | ||
# plotted along meridians (constant longitude). | ||
|
||
fig = pygmt.Figure() | ||
|
||
fig.basemap(region="g", projection="R15c", frame=["+thlines geographic", "af"]) | ||
# Add a horizontal line at a latitude of 70°N without specifying longitude limits | ||
fig.hlines(y=70, pen="1.5p,red3", label="Line 1") | ||
# Add a line at a latitude of 50°N with longitude limits at 20°E and 160°E | ||
fig.hlines(y=50, xmin=20, xmax=160, pen="1.5p,dodgerblue3", label="Line 2") | ||
# Add a horizontal line at a latitude of 30°S with longitude limits at 60°E | ||
# and 270°E | ||
fig.hlines(y=-30, xmin=60, xmax=270, pen="1.5p,gray30,-", label="Line 3") | ||
fig.legend() | ||
michaelgrund marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
fig.shift_origin(xshift="w+2c") | ||
|
||
fig.basemap(region="g", projection="R15c", frame=["+tvlines geographic", "af"]) | ||
# Add a vertical line at a longitude of 70°E without specifying latitude limits | ||
fig.vlines(x=70, pen="1.5p,red3", label="Line 1") | ||
# Add a vertical line at a longitude of 120°E with latitude limits at 50°S and 70°N | ||
fig.vlines(x=120, ymin=-50, ymax=70, pen="1.5p,dodgerblue3", label="Line 2") | ||
# Add a vertical line at a longitude of 230°E with latitude limits at 70°S | ||
# and 80°N | ||
fig.vlines(x=230, ymin=-70, ymax=80, pen="1.5p,gray30,-", label="Line 3") | ||
michaelgrund marked this conversation as resolved.
Show resolved
Hide resolved
|
||
fig.legend() | ||
|
||
fig.show() | ||
|
||
# %% | ||
# Polar coordinate system | ||
# ----------------------- | ||
# When using coordinate systems "horizontal" means lines are plotted as arcs along a | ||
michaelgrund marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# constant radius while "vertical" means lines are plotted as straight lines along | ||
# radius at a specified azimuth. | ||
|
||
fig = pygmt.Figure() | ||
|
||
fig.basemap(region=[0, 360, 0, 1], projection="P10c", frame=["+thlines polar", "af"]) | ||
# Add a horizontal line along a radius of 0.8 without specifying azimuth limits | ||
fig.hlines(y=0.8, pen="1.5p,red3", label="Line 1") | ||
# Add a horizontal line along a radius of 0.5 with azimuth limits at 30° and 160° | ||
fig.hlines(y=0.5, xmin=30, xmax=160, pen="1.5p,dodgerblue3", label="Line 2") | ||
# Add a horizontal line along a radius of 0.25 with azimuth limits at 60° | ||
# and 270° | ||
fig.hlines(y=0.25, xmin=60, xmax=270, pen="1.5p,gray30,-", label="Line 3") | ||
fig.legend() | ||
michaelgrund marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
fig.shift_origin(xshift="w+2c") | ||
|
||
fig.basemap(region=[0, 360, 0, 1], projection="P10c", frame=["+tvlines polar", "af"]) | ||
# Add a vertical line along at an azimuth of 120° without specifying radius limits | ||
fig.vlines(x=120, pen="1.5p,red3", label="Line 1") | ||
# Add a vertical line along at an azimuth of 190° with radius limits at 0.2 and 0.8 | ||
fig.vlines(x=190, ymin=0.2, ymax=0.8, pen="1.5p,dodgerblue3", label="Line 2") | ||
# Add a vertical line along at an azimuth of 320° with radius limits at 0.5 | ||
# and 0.9 | ||
michaelgrund marked this conversation as resolved.
Show resolved
Hide resolved
|
||
fig.vlines(x=320, ymin=0.5, ymax=0.9, pen="1.5p,gray30,-", label="Line 3") | ||
fig.legend() | ||
|
||
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.