Skip to content

Commit ba5cb77

Browse files
Move Figure.shift_origin to a standalone Python file (#2485)
Co-authored-by: Yvonne Fröhlich <[email protected]>
1 parent 35c121e commit ba5cb77

File tree

3 files changed

+42
-34
lines changed

3 files changed

+42
-34
lines changed

pygmt/figure.py

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -418,40 +418,6 @@ def show(self, dpi=300, width=500, method=None, waiting=0.5, **kwargs):
418418
)
419419
launch_external_viewer(pdf, waiting=waiting)
420420

421-
def shift_origin(self, xshift=None, yshift=None):
422-
"""
423-
Shift plot origin in x and/or y directions.
424-
425-
This method shifts the plot origin relative to the current origin
426-
by (*xshift*, *yshift*). Optionally, append the length unit (**c**,
427-
**i**, or **p**). Default unit if not given is **c** for centimeter.
428-
429-
Prepend **a** to shift the origin back to the original position after
430-
plotting, prepend **c** to center the plot on the center of the paper
431-
(optionally add shift), prepend **f** to shift the origin relative to
432-
the fixed lower left corner of the page, or prepend **r** [Default] to
433-
move the origin relative to its current location.
434-
435-
Detailed usage at
436-
:gmt-docs:`cookbook/options.html#plot-positioning-and-layout-the-x-y-options`
437-
438-
Parameters
439-
----------
440-
xshift : str
441-
Shift plot origin in x direction.
442-
yshift : str
443-
Shift plot origin in y direction.
444-
"""
445-
self._preprocess()
446-
args = ["-T"]
447-
if xshift:
448-
args.append(f"-X{xshift}")
449-
if yshift:
450-
args.append(f"-Y{yshift}")
451-
452-
with Session() as lib:
453-
lib.call_module(module="plot", args=" ".join(args))
454-
455421
def _preview(self, fmt, dpi, as_bytes=False, **kwargs):
456422
"""
457423
Grab a preview of the figure.
@@ -519,6 +485,7 @@ def _repr_html_(self):
519485
plot3d,
520486
rose,
521487
set_panel,
488+
shift_origin,
522489
solar,
523490
subplot,
524491
ternary,

pygmt/src/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
from pygmt.src.project import project
4444
from pygmt.src.rose import rose
4545
from pygmt.src.select import select
46+
from pygmt.src.shift_origin import shift_origin
4647
from pygmt.src.solar import solar
4748
from pygmt.src.sph2grd import sph2grd
4849
from pygmt.src.sphdistance import sphdistance

pygmt/src/shift_origin.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
"""
2+
shift_origin - Shift plot origin in x and/or y directions.
3+
"""
4+
5+
from pygmt.clib import Session
6+
7+
8+
def shift_origin(self, xshift=None, yshift=None):
9+
"""
10+
Shift plot origin in x and/or y directions.
11+
12+
This method shifts the plot origin relative to the current origin
13+
by (*xshift*, *yshift*). Optionally, append the length unit (**c**,
14+
**i**, or **p**). Default unit if not given is **c** for centimeters.
15+
16+
Prepend **a** to shift the origin back to the original position after
17+
plotting, prepend **c** to center the plot on the center of the paper
18+
(optionally add shift), prepend **f** to shift the origin relative to
19+
the fixed lower left corner of the page, or prepend **r** [Default] to
20+
move the origin relative to its current location.
21+
22+
Detailed usage at
23+
:gmt-docs:`cookbook/options.html#plot-positioning-and-layout-the-x-y-options`
24+
25+
Parameters
26+
----------
27+
xshift : str
28+
Shift plot origin in x direction.
29+
yshift : str
30+
Shift plot origin in y direction.
31+
"""
32+
self._preprocess() # pylint: disable=protected-access
33+
args = ["-T"]
34+
if xshift:
35+
args.append(f"-X{xshift}")
36+
if yshift:
37+
args.append(f"-Y{yshift}")
38+
39+
with Session() as lib:
40+
lib.call_module(module="plot", args=" ".join(args))

0 commit comments

Comments
 (0)