Skip to content
Draft
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
85e411c
Add code example for formating text as paragraph
yvonnefroehlich Apr 16, 2026
9839b8b
Remove execution permission
yvonnefroehlich Apr 16, 2026
a9efead
Fix typos
yvonnefroehlich Apr 16, 2026
8f7d1f5
Add link to gallery example
yvonnefroehlich Apr 20, 2026
d44dd9e
Merge branch 'main' into add-gallery-paragraph
yvonnefroehlich Apr 20, 2026
e0081b0
Add seperator at code beginning
yvonnefroehlich Apr 20, 2026
e71117c
Fix method highlighting
yvonnefroehlich Apr 21, 2026
ecc9232
Improve and extend intro text
yvonnefroehlich Apr 21, 2026
ecdba41
Improve title
yvonnefroehlich Apr 23, 2026
9e17927
Improve formulations
yvonnefroehlich Apr 23, 2026
025baeb
Add draft of PyGMT version of GMT example
yvonnefroehlich Apr 26, 2026
6f73c9c
Merge branch 'main' into add-gallery-paragraph
yvonnefroehlich Apr 26, 2026
fd044df
Add note regarding white space at end of strings for paragraph recogn…
yvonnefroehlich Apr 26, 2026
19eb614
Merge remote-tracking branch 'origin/add-gallery-paragraph' into add-…
yvonnefroehlich Apr 26, 2026
c8ee6f2
Merge branch 'main' into add-gallery-paragraph
yvonnefroehlich Apr 28, 2026
4280487
Merge branch 'main' into add-gallery-paragraph
yvonnefroehlich May 1, 2026
06e8147
Merge branch 'main' into add-gallery-paragraph
yvonnefroehlich Jul 3, 2026
8a01b35
Merge branch 'main' into add-gallery-paragraph
yvonnefroehlich Jul 4, 2026
df8ecd1
Typeset spaces and tabs
yvonnefroehlich Jul 7, 2026
2b62f3e
Add comment
yvonnefroehlich Jul 7, 2026
c999cbd
Merge branch 'main' into add-gallery-paragraph
yvonnefroehlich Jul 22, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 99 additions & 0 deletions examples/gallery/embellishments/paragraph.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
"""
Paragraphs of long text
=======================

To typeset long text as one or several paragraphs the :meth:`pygmt.Figure.paragraph`
method can be used. The ``parwidth`` and ``linespacing`` parameters allow to set
the width of the paragraph and line spacing, respectively. The desired text can
be provided using two ways to indicate a new paragraph:

(1) a single string separated by a blank line
(2) a list of strings, whereby each string needs to end with a white space
Comment thread
yvonnefroehlich marked this conversation as resolved.

During plotting the paragraphs are automatically separated by a blank line.

For details on text formatting see the gallery example
:doc:`Text formatting </gallery/embellishments/text_formatting>`.
"""

# %%
import pygmt

text = [
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. ",
"Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.",
]

fig = pygmt.Figure()
fig.basemap(region=[-5, 5, -5, 5], projection="X10c/10c", frame=True)

fig.paragraph(
text=text,
x=0,
y=0,
parwidth="4.5c",
linespacing="12p",
alignment="center",
justify="MC",
angle=45,
font="10p,Helvetica-Bold,steelblue",
fill="lightgray", # font color ignored
pen="1p,gray10", # font color ignored
)

fig.show()


# %%
text = [
"@_It was the best of times, it was the worst of times@_, it was the age of wisdom, it was the age of foolishness, it was the epoch of belief, it was the epoch of incredulity, it was the season of Light, it was the season of Darkness, it was the spring of hope, it was the winter of despair, we had everything before us, we had nothing before us, we were all going direct to Heaven, we were all going direct the other way -- ",
"in short, the period was so far like the present period, that some of its noisiest authorities insisted on its being received, for good or for evil, in the superlative degree of comparison only",
]

fig = pygmt.Figure()
fig.basemap(region=[-5, 5, -5, 5], projection="X15c/15c", frame=True)

fig.paragraph(
text=text,
x=0,
y=0,
parwidth="12c",
linespacing="18p",
alignment="center",
justify="MC",
font="16p,Times-Roman,red", # should now work with fill
fill="lightblue",
pen="2p",
# S="8p/-8p/darkblue", # not supported yet
# C="8p+tc", # not supported yet
Comment on lines +67 to +68

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.

Before continuing with this example in PyGMT we need to introduce the parameters for -S and -C.

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.

I think we don't have to reproduce the example exactly, so -S and -C are not needed.

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.

Agree, we can still extend the gallery example later to include this parameters if we feel this makes sense.

)

fig.show()


# %%
# taken from pygmt/tests/test_paragraph.py
text = [
" Paragraph 1: Two leading whitespaces. Three inline whitespaces. Two trailing whitespaces. ",
" Paragraph 2: One leading tab results in one indentation (four whitespaces by default).",
" Paragraph 3: Two leading tabs results in two indentation (eight whitespaces by default).",
"Paragraph 4: Multiple inline tabs are converted to multiple spaces. Trailing tabs have not effects. ",
"Paragraph 5: Mixing tabs and spaces. 2T3STST( ).",
"\nParagraph 6: Leading newline is converted to a space. Trailing newlines are converted to spaces.\n\n",
"\n\nParagraph 7: Multiple leading newline are converted to multiple spaces. xxx yyy zzz.",
"Paragraph 8: Newlines insiden a paragraph\nare converted to spaces.",
"Paragraph 9: This is the last paragraph.",
]

fig = pygmt.Figure()
fig.basemap(region=[-5, 5, -5, 5], projection="X15c/15c", frame=True)

fig.paragraph(
text=text,
x=0,
y=0,
parwidth="12c",
linespacing="18p",
)

fig.show()