Convenient methods to plot horizontal and vertical lines
See original GitHub issueDescription of the desired feature
matplotlib provides two methods, hlines and vlines, for plotting horizontal and vertical lines.
In PyGMT, we can plot any lines using the plot() method. However, for plotting horizontal and vertical lines, we have to prepare the input x and y arrays, which is not elegant.
Expected syntax:
Figure.hlines(y, xmin=None, xmax=None, pen=None, label=None)
Figure.vlines(x, ymin=None, ymax=None, pen=None, label=None)
An expected hlines example:
import pygmt
fig = pygmt.Figure()
fig.basemap(region=[0, 10, 0, 10], projection="X10c/10c", frame=True)
fig.hlines(1, label="line1")
fig.hlines([2, 3], pen="1p,blue", label="line2")
fig.hlines([4, 5], xmin=2, xmax=8, pen="1p,red", label="line3")
fig.hlines([6, 7], xmin=[2, 3], xmax=[8, 9], pen="1p,lightblue", label=["line4", "line5"])
fig.legend()
fig.show()
Expected output:

The above script is equivalent to the following script:
import pygmt
fig = pygmt.Figure()
fig.basemap(region=[0, 10, 0, 10], projection="X10c/10c", frame=True)
fig.plot(x=[0, 10], y=[1, 1], label="line1")
fig.plot(x=[0, 10], y=[2, 2], pen="1p,blue", label="line2")
fig.plot(x=[0, 10], y=[3, 3], pen="1p,blue")
fig.plot(x=[2, 8], y=[4, 4], pen="1p,red", label="line3")
fig.plot(x=[2, 8], y=[5, 5], pen="1p,red")
fig.plot(x=[2, 8], y=[6, 6], pen="1p,lightblue", label="line4")
fig.plot(x=[3, 9], y=[7, 7], pen="1p,lightblue")
fig.legend()
fig.show()
Are you willing to help implement and maintain this feature? Yes
Issue Analytics
- State:
- Created 3 years ago
- Comments:12 (12 by maintainers)
Top Results From Across the Web
Choosing the Most Convenient Method to Graph a Line
Strategy for Choosing the Most Convenient Method to Graph a Line. Consider the form of the equation. If it only has one variable,...
Read more >How To Graph Horizontal and Vertical Lines - YouTube
This algebra video tutorial provides a basic introduction on how to graph horizontal and vertical lines. Examples include graphs of the ...
Read more >Investigating Horizontal and Vertical Lines | CK-12 Foundation
The student will explore horizontal and vertical linear relationships. The student will graph and write these equations in real-world contexts.
Read more >Summary: Using Intercepts to Graph Lines - Lumen Learning
Draw the line. Choose the most convenient method to graph a line. Determine if the equation has only one variable. Then it is...
Read more >3.5 Use the Slope–Intercept Form of an Equation of a Line
Equations of this form have graphs that are vertical or horizontal lines. ... Strategy for choosing the most convenient method to graph a...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

@michaelgrund Haven’t made any progress lately; by all means have a stab at it!
Are you still working on that issue @willschlitzer? If not and if it’s ok for you I would like to continue with that 😉