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

Add Figure.hlines for plotting horizontal lines #923

Draft
wants to merge 33 commits into
base: main
Choose a base branch
from

Conversation

michaelgrund
Copy link
Member

@michaelgrund michaelgrund commented 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. Furthermore, currently the whole procedure is performed in a loop since it's not possible to pass multi-segment lines to the plot function so far (except using an input file). Please correct me if I'm wrong.

Reminders

  • Run make format and make check to make sure the code follows the style guide.
  • Add tests for new features or tests that would have caught the bug that you're fixing.
  • Add new public functions/methods/classes to doc/api/index.rst.
  • Write detailed docstrings for all functions/methods.
  • If adding new functionality, add an example to docstrings or tutorials.

Slash Commands

You can write slash commands (/command) in the first line of a comment to perform
specific operations. Supported slash commands are:

  • /format: automatically format and lint the code
  • /test-gmt-dev: run full tests on the latest GMT development version

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.
@michaelgrund michaelgrund marked this pull request as draft February 17, 2021 18:31
@michaelgrund michaelgrund added the feature Brand new feature label Feb 17, 2021
@seisman seisman added this to the 0.4.0 milestone Feb 17, 2021
@seisman seisman changed the title Add new modules to plot horizontal and vertical lines Add new modules to plot horizontal lines Feb 18, 2021
@seisman seisman changed the title Add new modules to plot horizontal lines Add Figure.hlines for plotting horizontal lines Feb 18, 2021
@seisman
Copy link
Member

seisman commented Feb 18, 2021

@michaelgrund Nice work! I just changed the PR title so that we can focus on one feature Figure.hlines in this PR.

@seisman
Copy link
Member

seisman commented Feb 18, 2021

Furthermore, currently the whole procedure is performed in a loop since it's not possible to pass multi-segment lines to the plot function so far (except using an input file).

It's possible to use np.NaN record to separate segments:

import numpy as np
import pygmt

x = np.array([2, 4, 4, np.NaN, 5, 6])
y = np.array([3, 5, 7, np.NaN, 4, 2])

fig = pygmt.Figure()
fig.basemap(region=[0, 10, 0, 10], frame=True)
fig.plot(x, y, pen="2p")
fig.show()

but I'm not sure if other features (lines with different colors) are supported.

@michaelgrund
Copy link
Member Author

Furthermore, currently the whole procedure is performed in a loop since it's not possible to pass multi-segment lines to the plot function so far (except using an input file).

It's possible to use np.NaN record to separate segments:

import numpy as np
import pygmt

x = np.array([2, 4, 4, np.NaN, 5, 6])
y = np.array([3, 5, 7, np.NaN, 4, 2])

fig = pygmt.Figure()
fig.basemap(region=[0, 10, 0, 10], frame=True)
fig.plot(x, y, pen="2p")
fig.show()

but I'm not sure if other features (lines with different colors) are supported.

Ok will check that and, if possible, adjust the code.

pygmt/src/hlines.py Outdated Show resolved Hide resolved
@willschlitzer
Copy link
Contributor

@GenericMappingTools/pygmt-maintainers This PR has been untouched since August; are we planning to get it wrapped up for v0.5.0?

@maxrjones
Copy link
Member

@GenericMappingTools/pygmt-maintainers This PR has been untouched since August; are we planning to get it wrapped up for v0.5.0?

I think the issues raised in #923 (review) will be a bit tricky to address, so I suggest v0.6.0.

@willschlitzer
Copy link
Contributor

@GenericMappingTools/pygmt-maintainers This PR has been untouched since August; are we planning to get it wrapped up for v0.5.0?

I think the issues raised in #923 (review) will be a bit tricky to address, so I suggest v0.6.0.

@michaelgrund I'm going to bump this back to v0.6.0

@willschlitzer willschlitzer modified the milestones: 0.5.0, 0.6.0 Oct 28, 2021
@michaelgrund
Copy link
Member Author

@GenericMappingTools/pygmt-maintainers This PR has been untouched since August; are we planning to get it wrapped up for v0.5.0?

I think the issues raised in #923 (review) will be a bit tricky to address, so I suggest v0.6.0.

@michaelgrund I'm going to bump this back to v0.6.0

That's fine @willschlitzer. Totally overlooked the review comments from @meghanrjones. Sorry for that.

@willschlitzer
Copy link
Contributor

willschlitzer commented Jan 28, 2022

@michaelgrund Are you hoping to get this in to the v0.6 release?

@michaelgrund
Copy link
Member Author

@michaelgrund Are you hoping to get this in to the v0.6 release?

Unfortunately not @willschlitzer ... Hope I can continue working on this PR end of February/beginning of March. Set the milestone to v0.7.0.

@michaelgrund michaelgrund modified the milestones: 0.6.0, 0.7.0 Jan 30, 2022
@seisman seisman modified the milestones: 0.7.0, 0.8.0 Jun 19, 2022
@seisman seisman modified the milestones: 0.8.0, 0.9.0 Dec 11, 2022
@seisman seisman modified the milestones: 0.9.0, 0.10.0 Mar 19, 2023
@weiji14 weiji14 removed their request for review May 25, 2023 01:05
@weiji14 weiji14 modified the milestones: 0.10.0, 0.11.0 Aug 24, 2023
@seisman seisman modified the milestones: 0.11.0, 0.12.0 Dec 11, 2023
@seisman seisman marked this pull request as draft December 11, 2023 09:17
@seisman seisman removed this from the 0.12.0 milestone Feb 26, 2024
@seisman seisman modified the milestone: 0.13.0 Apr 22, 2024
@seisman
Copy link
Member

seisman commented May 5, 2024

@michaelgrund I think we should get this feature done in v0.13.0. Are you still interested in working on this PR?

@seisman seisman added this to the 0.13.0 milestone May 5, 2024
@michaelgrund
Copy link
Member Author

@michaelgrund I think we should get this feature done in v0.13.0. Are you still interested in working on this PR?

Yes I am, after 3 years we should definitely bring this in v0.13.0.

Comment on lines +76 to +80
with Session() as lib:
# get limits from current map boundings if not given
# via xmin, xmax
x = np.array([[lib.extract_region()[0]], [lib.extract_region()[1]]])
x = np.repeat(x, list_length, axis=1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the Figure.region property (https://www.pygmt.org/dev/api/generated/pygmt.Figure.html#pygmt-figure):

Suggested change
with Session() as lib:
# get limits from current map boundings if not given
# via xmin, xmax
x = np.array([[lib.extract_region()[0]], [lib.extract_region()[1]]])
x = np.repeat(x, list_length, axis=1)
# get limits from current map boundings if not given via xmin, xmax
xmin, xmax = fig.region[0:2]
x = np.repeat([[xmin], [xmax]], list_length, axis=1)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Brand new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants