Figure.shift_origin: Support shifting origins temporarily when used as a context manager#2509
Figure.shift_origin: Support shifting origins temporarily when used as a context manager#2509
Conversation
Summary of changed imagesThis is an auto-generated report of images that have changed on the DVC remote
Image diff(s)DetailsAdded 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 |
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.
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.
| 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.
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.
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. |
yvonnefroehlich
left a comment
There was a problem hiding this comment.
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_origininto 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: