question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Convenient methods to plot horizontal and vertical lines

See original GitHub issue

Description 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: image

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:open
  • Created 3 years ago
  • Comments:12 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
willschlitzercommented, Feb 4, 2021

@michaelgrund Haven’t made any progress lately; by all means have a stab at it!

1reaction
michaelgrundcommented, Feb 4, 2021

Are you still working on that issue @willschlitzer? If not and if it’s ok for you I would like to continue with that 😉

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found