Skip to content
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

Convenient methods to plot horizontal and vertical lines #670

Open
seisman opened this issue Oct 24, 2020 · 12 comments
Open

Convenient methods to plot horizontal and vertical lines #670

seisman opened this issue Oct 24, 2020 · 12 comments
Labels
feature request New feature wanted good first issue Good for newcomers

Comments

@seisman
Copy link
Member

seisman commented Oct 24, 2020

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

@seisman seisman added the feature request New feature wanted label Oct 24, 2020
@seisman seisman added good first issue Good for newcomers help wanted Helping hands are appreciated labels Dec 7, 2020
@willschlitzer
Copy link
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.

@seisman
Copy link
Member Author

seisman commented Dec 10, 2020

I think this function is what you need:

def extract_region(self):

@willschlitzer
Copy link
Contributor

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

@seisman
Copy link
Member Author

seisman commented Dec 10, 2020

Yes.

@michaelgrund
Copy link
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 😉

@willschlitzer
Copy link
Contributor

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

michaelgrund added a commit that referenced this issue Feb 17, 2021
As discussed in #670 here's a new module (**hlines**) to plot a single or a set of horizontal lines with only defining the desired y-value(s). For discussion I only add the module for horizontal lines at the moment, however, the adjustments to prepare the same for vertical lines is done very quickly.
@weiji14
Copy link
Member

weiji14 commented Feb 20, 2021

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?

@seisman
Copy link
Member Author

seisman commented Feb 20, 2021

  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().

@nathandloria
Copy link
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.

@michaelgrund
Copy link
Member

michaelgrund commented Apr 7, 2021

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 ?

@maxrjones
Copy link
Member

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

@maxrjones maxrjones removed the help wanted Helping hands are appreciated label Aug 19, 2021
@maxrjones
Copy link
Member

@daroari is going to work on the vlines function to complement @michaelgrund's hlines function in pull request #923

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature wanted good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

6 participants