-
Notifications
You must be signed in to change notification settings - Fork 224
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
base: main
Are you sure you want to change the base?
Conversation
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 Nice work! I just changed the PR title so that we can focus on one feature |
It's possible to use
but I'm not sure if other features (lines with different colors) are supported. |
Ok will check that and, if possible, adjust the code. |
Co-authored-by: Yvonne Fröhlich <[email protected]>
@seisman related to your comment in #3593 (comment) should this new high-level method for specifically plotting horizontal lines be included in the "Plotting Lines" tutorial? Or do we want to have a separate gallery example showing the different interpretation of horizontal lines in different coordinate systems? |
I prefer this one |
The plan is to implement hlines and vlines, then add a gallery example for plotting horizontal and vertical lines in Cartesian, polar and geographic projections. |
Thanks for pushing this forward @seisman after almost 3.5 years. I'm fine with all the changes, especially with removing too complicated parts I added initially. Since I'm the author of this PR I cannot give an approval.
If I remember correctly the gallery example I provided within this PR was the left one in the example figure of the first post. After implementing |
I've marked this PR as "final review call", but will keep this PR open for more days since most of you are busy with the AGU workshop. Please 👍 if you have time reviewing this PR and think it's ready for merge. Or we can revisit the PR after AGU. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
Description of proposed changes
This PR implements the
Figure.hlines
method to plot horizontal line(s). This is a high-level wrapper ofFigure.plot
, and is inspired bymatplotlib.pyplot.hlines
.Address #670.
Features
y
)xmin
/xmax
, and then default to the x-limits of the current plot (i.e.,fig.region[0:2]
)pen
label
no_clip
//transparency
perspective
are also supportedLimitations
pen
/label
is allowed. It's possible to allow different pen or label (by passing a sequence of pen or label), but I feel it makes the codes too complicated. Users who need different pens/labels can callFigure.hlines
multiple times.Figure.plot
multiple times in a loop. As mentioned in Add Figure.hlines for plotting horizontal lines #923 (comment), it's possible to usenp.nan
as separators for each line, then we can callFigure.plot
once. However, GMT will complain aboutNaN
records when plotting lines in geographic projections because GMT needs to resample the lines before plotting.npoints=2
: Line is not plotted, because in geographic projections, longitude is periodic, so longitude 0=360.npoints=3
: i.e., passingx=[0, 180, 360]
, only one minor arc is drawnnpoints=4
: i.e., passingx=[0, 90, 180, 360]
, worksExample
Here is an example showing how it works in Cartesian/polar/geographic projections. See the tests for more examples.
Preview: https://pygmt-dev--923.org.readthedocs.build/en/923/api/generated/pygmt.Figure.hlines.html
Reminders
make format
andmake check
to make sure the code follows the style guide.doc/api/index.rst
.Slash Commands
You can write slash commands (
/command
) in the first line of a comment to performspecific operations. Supported slash command is:
/format
: automatically format and lint the code