Skip to content

Add Figure.paragraph to typeset one or multiple paragraph of text strings#3709

Merged
seisman merged 22 commits intomainfrom
feature/paragraph
Apr 10, 2026
Merged

Add Figure.paragraph to typeset one or multiple paragraph of text strings#3709
seisman merged 22 commits intomainfrom
feature/paragraph

Conversation

@seisman
Copy link
Copy Markdown
Member

@seisman seisman commented Dec 24, 2024

Initial implementation for the Figure.paragraph method, which wraps the text module's -M option.

Related to #3710.

Preview:

Example

import pygmt

fig = pygmt.Figure()
fig.basemap(region=[0, 10, 0, 10], projection="X10c/10c", frame=True)
fig.paragraph(
    x=4,
    y=4,
    text="This is a long paragraph. " * 10,
    parwidth="5c",
    linespacing="12p",
    font="12p",
)
fig.show()

map

@seisman seisman force-pushed the feature/paragraph branch from bbb0de1 to 43d49fb Compare January 6, 2025 04:17
@seisman seisman added the feature Brand new feature label Jan 6, 2025
@seisman seisman force-pushed the feature/paragraph branch from 43d49fb to a617468 Compare January 6, 2025 04:42
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Jan 6, 2025

Summary of changed images

This is an auto-generated report of images that have changed on the DVC remote

Status Path
added pygmt/tests/baseline/test_paragraph.png
added pygmt/tests/baseline/test_paragraph_multiple_paragraphs_blankline.png
added pygmt/tests/baseline/test_paragraph_multiple_paragraphs_list.png

Image diff(s)

Details

Added images

  • test_paragraph.png

  • test_paragraph_multiple_paragraphs_blankline.png

  • test_paragraph_multiple_paragraphs_list.png

Modified images

Path Old New

Report last updated at commit 23dad7b

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a new high-level Figure.paragraph method to typeset one or multiple paragraphs by wrapping GMT text module paragraph mode (-M), plus associated tests, baselines, and documentation wiring.

Changes:

  • Implement pygmt.Figure.paragraph (new pygmt/src/paragraph.py) using a virtualfile multi-segment input and text -M.
  • Add mpl image comparison tests and baseline artifacts for single- and multi-paragraph inputs.
  • Expose the new method in the Figure API and documentation index, and cross-link from text docs.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
pygmt/src/paragraph.py New Figure.paragraph implementation (builds text -M input via StringIO + virtual file).
pygmt/src/__init__.py Exports paragraph so it can be attached to Figure.
pygmt/figure.py Adds paragraph to the methods imported onto Figure.
pygmt/src/text.py Adds a doc cross-reference from text to Figure.paragraph.
doc/api/index.rst Adds Figure.paragraph to the API listing.
pygmt/tests/test_paragraph.py Adds image tests covering single paragraph and two multi-paragraph input styles.
pygmt/tests/baseline/*.png.dvc Adds DVC pointers for new image baselines.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

seisman and others added 3 commits April 2, 2026 18:37
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@seisman seisman added the needs review This PR has higher priority and needs review. label Apr 3, 2026
@seisman seisman marked this pull request as ready for review April 3, 2026 03:55
@seisman seisman requested a review from a team April 6, 2026 12:35
Copy link
Copy Markdown
Member

@yvonnefroehlich yvonnefroehlich left a comment

Choose a reason for hiding this comment

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

As this is probaly the first implemention of this new method, clearance (and other parameters) will be add in a later PR, or?

@seisman
Copy link
Copy Markdown
Member Author

seisman commented Apr 8, 2026

As this is probaly the first implemention of this new method, clearance (and other parameters) will be add in a later PR, or?

Yes, this PR focuses on the required and frequently used parameters only.

@seisman seisman requested a review from a team April 9, 2026 17:00
Copy link
Copy Markdown
Member

@yvonnefroehlich yvonnefroehlich left a comment

Choose a reason for hiding this comment

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

Looks good to me!

On side questions: Using text in line 1 \n text in line 2 to get a new line is still not supported. As far as I understand it, two paragraphs are automatically seperated by a blank line via \n\n.

Comment on lines +76 to +78
pen
Set the pen used to draw a rectangle around the paragraph [Default is
``"0.25p,black,solid"``].
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In case of multiple paragraphs, the entier text is surrounded by a box, or does each paragraph gets its own box?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

the entier text is surrounded by a box

This is the answer.

@seisman
Copy link
Copy Markdown
Member Author

seisman commented Apr 10, 2026

On side questions: Using text in line 1 \n text in line 2 to get a new line is still not supported.

Do you mean in Figure.text? Yes, it's not supported, and it's also difficult to support in GMT.

As far as I understand it, two paragraphs are automatically seperated by a blank line via \n\n.

Yes.

@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 Apr 10, 2026
@seisman seisman removed the final review call This PR requires final review and approval from a second reviewer label Apr 10, 2026
@seisman seisman merged commit d4a006c into main Apr 10, 2026
21 of 25 checks passed
@seisman seisman deleted the feature/paragraph branch April 10, 2026 17:15
@seisman seisman restored the feature/paragraph branch April 10, 2026 17:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature Brand new feature

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants