Allow export of panel size

Open
#4,204 3 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
python

Research direction

Start by reading the existing fig.shift_origin() behavior and the Session calls that expose plot dimensions in inches. Trace how Figure methods access the current panel size, then define the panel_dimensions('c') behavior shown in the example. Done means callers can retrieve the current panel width and height in the requested units and use the height for a later projection.

Written by the indexing model from the issue text.

Description

feature request

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

Dominant language
Python
Stars
882
Forks
261
Avg merge
1d 3h
Merged PRs (30d)
29

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from GenericMappingTools/pygmt

All issues in GenericMappingTools/pygmt

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.