pygmt.Figure.shift_origin

Figure.shift_origin(xshift=None, yshift=None)

Shift the plot origin in x and/or y directions.

The shifts can be permanent or temporary. If used as a standalone method, the shifts are permanent and apply to all subsequent plots. If used as a context manager, the shifts are temporary and only apply to the block of code within the context manager.

  1. Use as a standalone method to shift the plot origin permanently:

    fig.shift_origin(...)
    ...  # Other plot commands
    
  2. Use as a context manager to shift the plot origin temporarily:

    with fig.shift_origin(...):
        ...  # Other plot commands
        ...
    

The shifts xshift and yshift in x and y directions are relative to the current plot origin. The default unit for shifts is centimeters (c) but can be changed to other units via PROJ_LENGTH_UNIT. Optionally, append the length unit (c for centimeters, i for inches, or p for points) to the shifts.

For xshift, a special character w can also be used, which represents the bounding box width of the previous plot. The full syntax is [[±][f]w[/d]±]xoff, where optional signs, factor f and divisor d can be used to compute an offset that may be adjusted further by ±xoff. Assuming that the previous plot has a width of 10 centimeters, here are some example values for xshift:

  • "w": x-shift is 10 cm

  • "w+2c": x-shift is 10+2=12 cm

  • "2w+3c": x-shift is 2*10+3=23 cm

  • "w/2-2c": x-shift is 10/2-2=3 cm

Similarly, for yshift, a special character h can also be used, which is the bounding box height of the previous plot.

Note: The previous plot bounding box refers to the last object plotted, which may be a basemap, image, logo, legend, colorbar, etc.

Parameters:
  • xshift (float | str | None, default: None) – Shift plot origin in x direction.

  • yshift (float | str | None, default: None) – Shift plot origin in y direction.

Examples

Shifting the plot origin permanently:

>>> import pygmt
>>> fig = pygmt.Figure()
>>> fig.basemap(region=[0, 5, 0, 5], projection="X5c/5c", frame=True)
>>> # Shift the plot origin in x direction by 6 cm
>>> fig.shift_origin(xshift=6)
<contextlib._GeneratorContextManager object at ...>
>>> fig.basemap(region=[0, 7, 0, 5], projection="X7c/5c", frame=True)
>>> # Shift the plot origin in x direction based on the previous plot width.
>>> # Here, the width is 7 cm, and xshift is 8 cm.
>>> fig.shift_origin(xshift="w+1c")
<contextlib._GeneratorContextManager object at ...>
>>> fig.basemap(region=[0, 10, 0, 5], projection="X10c/5c", frame=True)
>>> fig.show()

Shifting the plot origin temporarily:

>>> fig = pygmt.Figure()
>>> fig.basemap(region=[0, 5, 0, 5], projection="X5c/5c", frame=True)
>>> # Shift the plot origin in x direction by 6 cm temporarily. The plot origin will
>>> # revert back to the original plot origin after the block of code is executed.
>>> with fig.shift_origin(xshift=6):
...     fig.basemap(region=[0, 5, 0, 5], projection="X5c/5c", frame=True)
>>> # Shift the plot origin in y direction by 6 cm temporarily.
>>> with fig.shift_origin(yshift=6):
...     fig.basemap(region=[0, 5, 0, 5], projection="X5c/5c", frame=True)
>>> # Shift the plot origin in x and y directions by 6 cm temporarily.
>>> with fig.shift_origin(xshift=6, yshift=6):
...     fig.basemap(region=[0, 5, 0, 5], projection="X5c/5c", frame=True)
>>> fig.show()

Examples using pygmt.Figure.shift_origin

3-D scatter plots

3-D scatter plots

Blockmean

Blockmean

Scatter plot with histograms

Scatter plot with histograms

Cross-section along a transect

Cross-section along a transect

Clipping grid values

Clipping grid values

Calculating grid gradient and radiance

Calculating grid gradient and radiance

Connection lines

Connection lines

Envelope

Envelope

Horizontal and vertical lines

Horizontal and vertical lines

Line segment caps and joints

Line segment caps and joints

Polar

Polar

Cartesian histograms

Cartesian histograms

Configuring PyGMT defaults

Configuring PyGMT defaults

Creating legends

Creating legends

Making subplots

Making subplots

Coastlines and borders

Coastlines and borders

Plotting polygons

Plotting polygons

Plotting text

Plotting text