Repository navigation
Closed
Labels
feature requestNew feature wanted
Milestone
Description
This issue serves as the central place for discussing and tracking the implementation of the Figure.paragraph method in PyGMT. The issue will be closed when the initial implementation is complete. Progress is tracked at PyGMT: Wrapping GMT modules.
Figure.paragraph is a high-level wrapper of GMT's text module -M option to typeset one or multiple paragraphs in a plot.
Documentation
- GMT: https://docs.generic-mapping-tools.org/dev/text.html
- GMT.jl: https://www.generic-mapping-tools.org/GMTjl_doc/documentation/modules/text/
- PyGMT: https://www.pygmt.org/dev/api/generated/pygmt.Figure.paragraph.html
GMT Option Flags and Modifieres
☑️: Implemented; ⬜: To be implemented/discussed; Strikethrough: Won't implement.
-
<table>: Add Figure.paragraph to typeset one or multiple paragraph of text strings #3709 -
-J -
-R -
-A -
-B -
-C -
-D -
-F-
+a: set angle Add Figure.paragraph to typeset one or multiple paragraph of text strings #3709 -
+c: -
+f: set font Add Figure.paragraph to typeset one or multiple paragraph of text strings #3709 -
+j: set justify Add Figure.paragraph to typeset one or multiple paragraph of text strings #3709 -
: Can't be used in paragraph mode.+h|l|r|z|t
-
-
-G:fillAdd Figure.paragraph to typeset one or multiple paragraph of text strings #3709 -
-L -
-M: paragraph mode Add Figure.paragraph to typeset one or multiple paragraph of text strings #3709 -
-N -
-Q -
-S -
: Use~~-UFigure.timestamp. -
-V:verboseAdd Figure.paragraph to typeset one or multiple paragraph of text strings #3709 -
-W:penAdd Figure.paragraph to typeset one or multiple paragraph of text strings #3709 -
: Use~~-XFigure.shift_origin. -
: Use~~-YFigure.shift_origin. -
: Not implemented for paragraph mode-Z -
-a -
-c:panelAdd Figure.paragraph to typeset one or multiple paragraph of text strings #3709 -
-e -
-f -
-h -
-it -
: This option is not implemented in paragraph mode.-p -
-qi -
-t:transparencyAdd Figure.paragraph to typeset one or multiple paragraph of text strings #3709 -
-wy -
-:
Notes on Input Formats
text's -M option means "paragraph mode". In this mode, the input file must be multi-segment files. Segments are separated by a special record whose first character must be flag [Default is >]. Multiple paragraphs are separated with a blank line. Its format is like:
> x y [font angle justify] linespace parwidth parjust
text for paragraph1
text for paragraph2
> x y [font angle justify] linespace parwidth parjust
text for paragraph3
x/y: position of the paragraphfont/angle: font and angle of the text [Requires-F]justify: justification of the paragraph box [Requires-F]linespace: line spacingparwidth: paragraph widthparjust: text justification in the paragraph, can be l(eft), c(enter), r(ight), or j(ustified)
Notes:
- Multiple paragraphs should be separated by a blank line when passing to GMT. A sequence of string is the most Pythonic way to represent multiple paragraphs.
- When typesetting multiple paragraphs, each paragraph can have its own font/angle/justify/linespace/parwidth/parjust. It means the corresponding parameters should accept a sequence as input. I think it will makes codes much complicated, so prefer not to support it. Users who need different styles for different paragraphs can call
Figure.paragraphmultiple times. - Passing a plaintext file is not supported. I prefer not to support it anyway.
Linked Pull Requests
- Initial feature implementation Add Figure.paragraph to typeset one or multiple paragraph of text strings #3709 @seisman
- Add a tutorial or gallery example
Related Issues and Discussions
Metadata
Metadata
Assignees
Labels
feature requestNew feature wanted
Type
Projects
- StatusShow more project fieldsNo status
- StatusShow more project fieldsDone
Activity
seisman commentedon Apr 27, 2026
As found in #4602, the GMT behavior for whitespaces is a little weird in PyGMT. Here is a GMT CLI script to understand the behavior:
Here is the corresponding PyGMT script:
Here are the outputs:
Summary of the behavior in GMT:
seisman commentedon Apr 28, 2026
As shown in the examples above, the behaviors of GMT and PyGMT differ substantially. It is important to note, however, that the GMT CLI reads text from plain files, whereas PyGMT reads text from virtual files.
In practice, I find both GMT’s behavior and the current behavior in PyGMT less than ideal. Text strings are typeset in unexpected ways which likely will surprise and confuse users. It's also difficult to achieve precise layouts, for example, when reproducing code-like formatting (see: https://github.com/GenericMappingTools/pygmt-paper-figures/blob/main/Fig1_PyGMT_GMT_comparison.ipynb).
In my view, users should be responsible for the content they provide to PyGMT, and PyGMT should render text exactly as given, i.e., following a WYSIWYT (“what you see is what you type”) principle.
Edit:
I'll open a POC PR for it.POC PR at #4605. The result isThe new behaviors implemented in PR #4605 are:
tab_width\nmakes no sense inside a paragraph, so it's removed.