Skip to content

Conversation

@seisman
Copy link
Member

@seisman seisman commented Aug 10, 2025

This PR provides a Pythonic interface for the -D option:

The full syntax is:

-D[g|j|J|n|x]<refpoint>[+w<width>[/<height>]][+j<justify>][+l<spacing>][+o<dx>[/<dy>]]
  • [g|j|J|n|x]<refpoint>[+j<justify>][+o<dx>[/<dy>]]: position and Position class
  • +w: width and height
  • +l: line_spacing. GMT uses spacing, but I feel line_spacing is better.

Preview:

Related to #4249.

@seisman seisman changed the title Figure.legend: Add parameters position/width/height/spacing to specify legend position and properties Figure.legend: Add parameters position/width/height/line_spacing to specify legend position and properties Dec 10, 2025
Base automatically changed from params/position to main December 11, 2025 01:54
@seisman seisman marked this pull request as ready for review December 11, 2025 03:48
@seisman seisman added the needs review This PR has higher priority and needs review. label Dec 11, 2025
@seisman seisman requested a review from a team December 11, 2025 03:58
@seisman seisman mentioned this pull request Dec 11, 2025
19 tasks
@seisman seisman added final review call This PR requires final review and approval from a second reviewer and removed needs review This PR has higher priority and needs review. labels Dec 18, 2025
@seisman
Copy link
Member Author

seisman commented Dec 18, 2025

@GenericMappingTools/pygmt-maintainers Please give this PR a final review.

I think the key points we need to reach agreement on are:

  • The parameter name line_spacing for the +l modifier. Although GMT uses spacing, this term is commonly associated with x– and y–spacings (e.g., in xyz2grd), which could be confusing in this context.
  • The default behavior when position is not specified. In PyGMT, the legend is placed in the top-left corner with a 0.2 cm offset by default, whereas GMT itself does not define a default legend position.

Path(specfile.name).write_text(legend_spec, encoding="utf-8")
fig = Figure()
fig.basemap(projection="x6i", region=[0, 1, 0, 1], frame=True)
fig.legend(specfile.name, position="JMC+jMC+w5i")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JMC+jMC is equivalent to jMC.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Improving an existing feature final review call This PR requires final review and approval from a second reviewer

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants