pygmt.clib.Session.extract_region

Session.extract_region(self)[source]

Extract the WESN bounding box of the currently active figure.

Retrieves the information from the PostScript file, so it works for country codes as well.

Returns:
* wesn : 1d array

A 1D numpy array with the west, east, south, and north dimensions of the current figure.

Examples

>>> import pygmt
>>> fig = pygmt.Figure()
>>> fig.coast(region=[0, 10, -20, -10], projection="M6i", frame=True,
...           land='black')
>>> with Session() as lib:
...     wesn = lib.extract_region()
>>> print(', '.join(['{:.2f}'.format(x) for x in wesn]))
0.00, 10.00, -20.00, -10.00

Using ISO country codes for the regions (for example 'US.HI' for Hawaii):

>>> fig = pygmt.Figure()
>>> fig.coast(region='US.HI', projection="M6i", frame=True,
...           land='black')
>>> with Session() as lib:
...     wesn = lib.extract_region()
>>> print(', '.join(['{:.2f}'.format(x) for x in wesn]))
-164.71, -154.81, 18.91, 23.58

The country codes can have an extra argument that rounds the region a multiple of the argument (for example, 'US.HI+r5' will round the region to multiples of 5):

>>> fig = pygmt.Figure()
>>> fig.coast(region='US.HI+r5', projection="M6i", frame=True,
...           land='black')
>>> with Session() as lib:
...     wesn = lib.extract_region()
>>> print(', '.join(['{:.2f}'.format(x) for x in wesn]))
-165.00, -150.00, 15.00, 25.00