-
Notifications
You must be signed in to change notification settings - Fork 228
Figure.shift_origin: Support shifting origins temporarily when used as a context manager #2509
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
Conversation
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 a75a440 |
cda4b8c
to
3c57bf5
Compare
…s a context manager
3c57bf5
to
c15f549
Compare
Finally make it work as expected. @GenericMappingTools/pygmt-maintainers Please try the new |
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!
Co-authored-by: Michael Grund <23025878+michaelgrund@users.noreply.github.com>
It would be better if @yvonnefroehlich and @weiji14 could give this PR a review, since it's a big change to the |
pygmt/src/shift_origin.py
Outdated
Shift plot origin in x and/or y directions. | ||
Shift the plot origin in x and/or y directions. | ||
|
||
The shifts can be temporary or permanent. If used as a context manager, the shifts |
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.
Wonder if it is better to change the order to first mention permanent and then temporary, as in the examples at the end. At least I would have this always in the same order.
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.
Sounds good. Done in 0d489dc.
For *xshift*, a special character **w** can also be used, which represents the | ||
bounding box **width** of the previous plot. The full syntax is |
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.
How do w (x direction) and h (y direction) work for the temporary option? Is this also refering to the previous plot, or actually the current plot? In case it refers to the previous plot, what is used if the current plot is the first plot?
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.
How do w (x direction) and h (y direction) work for the temporary option? Is this also refering to the previous plot, or actually the current plot?
It always refers to the previous plot.
In case it refers to the previous plot, what is used if the current plot is the first plot?
Figure.shift_origin
has no effects if it is called before any plotting methods:
import pygmt
fig = pygmt.Figure()
with fig.shift_origin(xshift="w+2c"):
fig.basemap(region=[0, 1, 0, 1], projection="X3c", frame=0)
fig.show()
Co-authored-by: Yvonne Fröhlich <94163266+yvonnefroehlich@users.noreply.github.com>
Will merge this PR in 24 hours if no further comments. |
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.
Should be fine from my side!
Thanks for all your reviews. I've merged this PR. |
See #2401 for context.
In the old versions,
Figure.shift_origin(...)
can only shift origins permanently, but sometimes users may want to shift origins temporarily (i.e., shifting the origins to a new location, plotting and then reverting back to the previous origins).This PR refactors
Figure.shift_origin
into a context manager so that it can shift origins permanently when used as a regular method or temporarily when used as a context manager.Old documentation: https://www.pygmt.org/v0.14.0/api/generated/pygmt.Figure.shift_origin.html
Preview the new documentation: https://pygmt-dev--2509.org.readthedocs.build/en/2509/api/generated/pygmt.Figure.shift_origin.html
Enhanced syntax
The new syntax is:
Examples
Use as a regular method:
Use as a context manager: