Figure.shift_origin: Allow shifting the origin back to the original position after plotting #2401
Open
1 of 4 tasks
Labels
feature request
New feature wanted
Background
The full syntax of GMT's
-X
and-Y
options is (https://docs.generic-mapping-tools.org/dev/gmt.html#xy-full):-X[a|c|f|r][xshift]
.As mentioned in the upstream issue GenericMappingTools/gmt#7296,
-Xc
and-Xf
make no sense in modern mode. So, we only focus on-Xr
(the same as-X
) and-Xa
in PyGMT.-Xr
: move the origin relative to its current location.-Xa
: move the origin relative to its current location, and move the origin back to the original position after plottingThe following GMT bash script shows the behavior of
-Xr
and-Xa
:For
-Xr
, the output image is:For
-Xa
, the output image is:Limitations of
Figure.shift_origin()
Currently, the
Figure.shift_origin()
function can shift the origin but can't move the origin back to the original position, as shown by the following PyGMT script:With
xshift="a6c"
, theFigure.shift_origin()
call shifts the plotting origin by 6 cm in X direction and then move the plotting origin back before the 2ndFigure.basemap
call. Thus, the above script produces an image like:Enhancement of
Figure.shift_origin()
Figure.shift_origin
should be able to revert to its original position after plotting. This can be done using thewith Figure.shift_origin():
syntax, similar to thepygmt.config()
function.The new syntax can be:
TODOs
shift_origin
function is in thepygmt/figure.py
file. I think it makes sense to move it topygmt/src/shift_origin.py
because the function will be much longer now. (Move Figure.shift_origin to a standalone Python file #2485)with Figure.shift_origin(xshift="1c")
syntax. The implementation is very similar to thepygmt.config()
function. We just need to remember the shift parameters and then do the inverse shift when exiting the context manager (e.g., usexshift="-1c"
when exiting). (@seisman)Are you willing to help implement and maintain this feature?
Maybe. This function should be easy to implement, so volunteers are welcomed and I'm glad to review this PR.
The text was updated successfully, but these errors were encountered: