How can I get the PyGMT figure size?

Hello everyone! I’m making some plots for a publication, and need them to be consistent in text size with the ones made through matplotlib. I’ve set the font size through pygmt.config, but I don’t know the reference size of the image in order to guarantee it’s scaled correctly in the manuscript. How can I get that information (or set it)? If I understand correctly, setting the size through basemap doesn’t set the size of the full image, only the map part.

Thank you very much!

I don’t think it’s possible in GMT or PyGMT. Maybe just save the image and check the width/height information from file properties?

As far as I know, it is possible to get the region of your plot directly and you can store it in a variable as an array.

Running verbose="i" within Figure.show gives you the “Figure dimensions” as output in your console, but the output cannot be directly stored in a variable. For these values, the frame annotations are also considered.

import pygmt

fig = pygmt.Figure()
fig.basemap(region=[-10, 10, 40, 50], projection="M5c", frame=True)
# fig.basemap(region=[-10, 10, 40, 50], projection="M5c", frame=0)
fig.show(verbose="i")

get_region = fig.region
print(get_region)

Output

for frame=True

psconvert [INFORMATION]: Processing C:/Users/Admin/.gmt/sessions/gmt_session.bcb9a7c58d00456980f5b0f5d3408b47/gmt_2.ps-...
psconvert [INFORMATION]: Find HiResBoundingBox ...
psconvert [INFORMATION]: Figure dimensions: Width: 175.086 points [6.17664 cm]  Height: 117.162 points [4.13321 cm]
psconvert [INFORMATION]: [2855.16 2867.26 3030.25 2984.42]...
psconvert [INFORMATION]: Convert to PNG...
[-10.  10.  40.  50.]

for frame=0

psconvert [INFORMATION]: Processing C:/Users/Admin/.gmt/sessions/gmt_session.c38e8f747112456ba7e7e8e4f94b5043/gmt_2.ps-...
psconvert [INFORMATION]: Find HiResBoundingBox ...
psconvert [INFORMATION]: Figure dimensions: Width: 142.98 points [5.04402 cm]  Height: 101.52 points [3.5814 cm]
psconvert [INFORMATION]: [2879.37 2879.37 3022.35 2980.89]...
psconvert [INFORMATION]: Convert to PNG...
[-10.  10.  40.  50.]