Skip to content

Convenient methods to plot horizontal and vertical lines #670

Closed
@seisman

Description

@seisman

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions