-
Notifications
You must be signed in to change notification settings - Fork 222
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. |
Summary of changed imagesThis is an auto-generated report of images that have changed on the DVC remote
Image diff(s)Added images
Modified images
Report last updated at commit 7a20b8c |
Co-authored-by: Yvonne Fröhlich <[email protected]>
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