Skip to content

Convenient methods to plot horizontal and vertical lines #670

Closed

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

Activity

  1. added
    feature request
    on Oct 24, 2020
  2. added
    good first issue
    help wanted
    on Dec 7, 2020
  3. willschlitzer commented on Dec 10, 2020

    @willschlitzer
    Contributor

    Is there any way to get basemap to return x/y min/max values to set as the endpoint values when calling hlines/vlines? I would like to give this a try but I can't get past how to plot the line to take up the range of the figure if the None defaults are used for the min/max values.

  4. seisman commented on Dec 10, 2020

    @seisman
    MemberAuthor

    I think this function is what you need:

    def extract_region(self):

  5. willschlitzer commented on Dec 10, 2020

    @willschlitzer
    Contributor

    Thanks! I assume you're talking about extract_region()?

  6. seisman commented on Dec 10, 2020

    @seisman
    MemberAuthor

    Yes.

  7. michaelgrund commented on Feb 4, 2021

    @michaelgrund
    Member

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

  8. willschlitzer commented on Feb 4, 2021

    @willschlitzer
    Contributor

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

  9. weiji14 commented on Feb 20, 2021

    @weiji14
    Member

    Just two quick questions:

    1. On organizing these higher level convenience functions. Do we want to keep them in the pygmt/src folder or somewhere else?

    2. Should the implementation of hlines and vlines be reusing some part of the fig.plot code? Or do we implement them from scratch as is being done in Add Figure.hlines for plotting horizontal lines #923?

  10. seisman commented on Feb 20, 2021

    @seisman
    MemberAuthor
    1. On organizing these higher level convenience functions. Do we want to keep them in the pygmt/src folder or somewhere else?

    I think we should put them in pygmt/src. To users and developers, they are the same as other modules/functions.

    1. Should the implementation of hlines and vlines be reusing some part of the fig.plot code? Or do we implement them from scratch as is being done in Add Figure.hlines for plotting horizontal lines #923?

    Do you mean Figure.hlines() should calling Figure.plot()? Ideally yes, but I'm not sure if Figure.hlines() can use the aliases of Figure.plot().

  11. nathandloria commented on Apr 7, 2021

    @nathandloria
    Contributor

    Hello! Thank you for the continued communication with our team (@cklima616 @munzekm @noorbuchi and I) as we decide where to go next in our class. I would just like to inquire about the availability of this issue? It seems very interesting and we would consider working on it if it is available still. Thanks again, we really do appreciate the cooperation.

  12. michaelgrund commented on Apr 7, 2021

    @michaelgrund
    Member

    Hey @nathandloria, I'm currently working on this in #923, so maybe you can find another interesting topic or issue like #549 (Add tutorial for plotting datetime inputs) as suggested by @weiji14 ?

  13. maxrjones commented on Aug 12, 2021

    @maxrjones
    Member

    @michaelgrund, are you planning to add vlines after #923? If so, I'll remove the help-wanted label.

  14. 2 remaining items

  15. removed
    good first issue
    on Nov 22, 2024
  16. added this to the 0.14.0 milestone on Nov 22, 2024
  17. pinned this issue on Dec 23, 2024
  18. unpinned this issue on Dec 28, 2024
  19. seisman commented on Dec 30, 2024

    @seisman
    MemberAuthor

    We have added Figure.hlines (#923) and Figure.vlines (#3726), but we still need one gallery example to tutorial for these two new functions.

  20. modified the milestones: 0.14.0, 0.15.0 on Dec 30, 2024
  21. added
    documentation
    help wanted
    on Dec 30, 2024
  22. removed this from the 0.15.0 milestone on Dec 31, 2024
  23. seisman commented on Feb 5, 2025

    @seisman
    MemberAuthor

    A gallery example was added in #3755. Closing.

  24. removed
    documentation
    help wanted
    on Feb 5, 2025
  25. added this to the 0.15.0 milestone on Feb 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature request

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions