Skip to content

DOC: Add gallery example to show text formatting #3987

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 27 commits into from
Jul 20, 2025
Merged
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
77330ce
Add code for text formatting gallery example
yvonnefroehlich Jun 21, 2025
760d5fd
Remove execution permission
yvonnefroehlich Jun 21, 2025
26f0c64
Follow code style
yvonnefroehlich Jun 21, 2025
4c5d25b
Split code
yvonnefroehlich Jun 21, 2025
33dc050
Add docs
yvonnefroehlich Jun 21, 2025
ec9a6a8
Fix typo
yvonnefroehlich Jun 21, 2025
74933b1
Use line length
yvonnefroehlich Jun 21, 2025
b622a53
Mention legnd in docs
yvonnefroehlich Jun 22, 2025
5a7d11f
Add comment
yvonnefroehlich Jun 22, 2025
7b980b2
Fix typo in formular
yvonnefroehlich Jun 22, 2025
45a74c9
Adjust figure dimensions
yvonnefroehlich Jun 22, 2025
48d045e
Mention title in doc
yvonnefroehlich Jun 22, 2025
084a036
Adjust figure dimensions and add comma
yvonnefroehlich Jun 22, 2025
15b2b8e
Update docs
yvonnefroehlich Jul 7, 2025
2462e99
Update docs
yvonnefroehlich Jul 7, 2025
a1ac875
Merge branch 'main' into add-gallery-textformat
yvonnefroehlich Jul 7, 2025
f693d35
Remove double white space
yvonnefroehlich Jul 7, 2025
98cf164
Update docs
yvonnefroehlich Jul 11, 2025
8513300
Merge branch 'main' into add-gallery-textformat
yvonnefroehlich Jul 11, 2025
02bd41a
Merge branch 'main' into add-gallery-textformat
yvonnefroehlich Jul 18, 2025
cde3f5e
Write complete sentence
yvonnefroehlich Jul 19, 2025
c05aa65
Write only letters within the words in small caps
yvonnefroehlich Jul 19, 2025
29086e8
Merge branch 'main' into add-gallery-textformat
yvonnefroehlich Jul 19, 2025
404bf4d
TEST - exclude image in legend tutorial
yvonnefroehlich Jul 19, 2025
ab0d6c5
Revert "TEST - exclude image in legend tutorial"
yvonnefroehlich Jul 19, 2025
3764dec
Fix line length
yvonnefroehlich Jul 19, 2025
c6d5f86
Adjust word
yvonnefroehlich Jul 20, 2025
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
41 changes: 41 additions & 0 deletions examples/gallery/embellishments/text_formatting.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"""
Text formatting
===============

There are various options for formatting text contained in a plot, e.g., text added via
:meth:`pygmt.Figure.text`, the plot title, labels of colorbars as well as Cartesian
axes, and legend entries. It's also possible to change the font as well as its color
and size only for specific characters of a longer text. The supported fonts are listed
at :doc:`Supported Fonts </techref/fonts>`. For an complete overview see
:doc:`Text Formatting </techref/text_formatting>`.
"""

# %%
import pygmt

fig = pygmt.Figure()
fig.basemap(region=[-1, 1, -4, 4], projection="X4c/5c", frame=0)

# Change font color for specific letters of the word "PyGMT":
# blue for "P", yellow for "y", and red for "GMT"
fig.text(x=0, y=3, text="@;63/124/173;P@;;@;255/212/59;y@;;@;238/86/52;GMT@;;")

# Change font size and style for one single character, respectively
fig.text(x=0, y=2, text="te@:15:x@::t tex@%Courier-Oblique%t@%%")

# Use superscript
fig.text(x=0, y=1, text="E = mc@+2@+")

# Use subscripts and Greek letters
fig.text(x=0, y=0, text="@~s@~@-ij@- = c@-ijkl@- @~e@~@-kl@-")

# Combine two characters above each other
fig.text(x=0, y=-1, text="@!_~")

# Underline the text
fig.text(x=0, y=-2, text="This is @_underlined@_ text")

# Use small caps
fig.text(x=0, y=-3, text="T@#ext@# in S@#mall@# C@#aps@#")

fig.show()
Loading