You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If the projections that you are using are not initially defined by a given height and width, then it is difficult to extract the dimensions of the plot in cm. This is an issue, for example, if panel A is an oblique mercator projection (with a projection defined by a central point and a rotation, and a region given as a top left and bottom right coordinate) and you would like panel B to be the same height (where the projection is f'X{width}c/{height}c').
As fig.shift_origin() has included an option to get the plot size in inches since v15.0.0 :
with Session() as lib:
lib.call_module(module="plot", args=build_arg_list(kwdict))
_xshift = lib.get_common("X") # False or xshift in inches
_yshift = lib.get_common("Y") # False or yshift in inches
it feels like it should be possible to include a function where _xshift and _yshift can be exported as variables.
Example use:
proj = f"Oa{center_lon}/{center_lat}/55/{width}c+v" ##### PANEL HEIGHT IN CM NOT DEFINED
region = f"{tl_lon}/{tl_lat}/{br_lon}/{br_lat}+r"
fig = pygmt.Figure()
fig.coast(region=region, projection=proj, land="gray80", water="steelblue", area_thresh=1000)
panelA_width, panelA_height = fig.panel_dimensions('c') ##### RETURN PANEL SIZE IN CM
fig.shift_origin(width='w')
fig.basemap(region=[0, xmax, 0, ymax], projection=f'X{panelb_width}c/{panelA_height}c', frame=['WSne', 'xafg2', 'yafg1.0']) ##### ENSURE HEIGHT OF NEW PANEL MATCHES PANEL A
Are you willing to help implement and maintain this feature? Yes
Please make sure you filled out the template with as much detail as possible. You might also want to take a look at our contributing guidelines and code of conduct.
As illustrated in the script, the mapproject module can be used to calculate the distance (in centimeters) from any point to the plotting origin. In this example, the point corresponds to the top-right corner of the basemap. The output from mapproject is stored in the variables width and height, which can then be used to position additional map elements.
The resulting image is shown below:
Although it remains unclear whether the feature proposed by @JackDMcGrath should be implemented in PyGMT, it would at least be beneficial to wrap the mapproject module, as first requested in #1986.
@JackDMcGrath Please let us know if you'd like to help wrapping the mapproject module in PyGMT.
Activity
seisman commentedon Nov 12, 2025
I guess this is a feature request to PyGMT, so transfering it to the pygmt repository.
github-actions commentedon Nov 12, 2025
👋 Thanks for opening your first issue here!
Please make sure you filled out the template with as much detail as possible. You might also want to take a look at our contributing guidelines and code of conduct.
seisman commentedon Nov 13, 2025
Currently, PyGMT does not provide this functionality and also does not store map dimensions.
The example below demonstrates how this can be achieved using the GMT command-line interface (CLI):
As illustrated in the script, the
mapprojectmodule can be used to calculate the distance (in centimeters) from any point to the plotting origin. In this example, the point corresponds to the top-right corner of the basemap. The output frommapprojectis stored in the variableswidthandheight, which can then be used to position additional map elements.The resulting image is shown below:
Although it remains unclear whether the feature proposed by @JackDMcGrath should be implemented in PyGMT, it would at least be beneficial to wrap the
mapprojectmodule, as first requested in #1986.@JackDMcGrath Please let us know if you'd like to help wrapping the
mapprojectmodule in PyGMT.