|
| 1 | +""" |
| 2 | +Text formatting |
| 3 | +=============== |
| 4 | +
|
| 5 | +There are various options for formatting text contained in a plot, e.g., text added via |
| 6 | +:meth:`pygmt.Figure.text`, the plot title, labels of colorbars as well as Cartesian |
| 7 | +axes, and legend entries. It's also possible to change the font as well as its color |
| 8 | +and size only for specific characters of a longer text. The supported fonts are listed |
| 9 | +at :doc:`Supported Fonts </techref/fonts>`. For an complete overview see |
| 10 | +:doc:`Text Formatting </techref/text_formatting>`. |
| 11 | +""" |
| 12 | + |
| 13 | +# %% |
| 14 | +import pygmt |
| 15 | + |
| 16 | +fig = pygmt.Figure() |
| 17 | +fig.basemap(region=[-1, 1, -4, 4], projection="X4c/5c", frame=0) |
| 18 | + |
| 19 | +# Change font color for specific letters of the word "PyGMT": |
| 20 | +# blue for "P", yellow for "y", and red for "GMT" |
| 21 | +fig.text(x=0, y=3, text="@;63/124/173;P@;;@;255/212/59;y@;;@;238/86/52;GMT@;;") |
| 22 | + |
| 23 | +# Change font size and style for one single character, respectively |
| 24 | +fig.text(x=0, y=2, text="te@:15:x@::t tex@%Courier-Oblique%t@%%") |
| 25 | + |
| 26 | +# Use superscript |
| 27 | +fig.text(x=0, y=1, text="E = mc@+2@+") |
| 28 | + |
| 29 | +# Use subscripts and Greek letters |
| 30 | +fig.text(x=0, y=0, text="@~s@~@-ij@- = c@-ijkl@- @~e@~@-kl@-") |
| 31 | + |
| 32 | +# Combine two characters above each other |
| 33 | +fig.text(x=0, y=-1, text="@!_~") |
| 34 | + |
| 35 | +# Underline the text |
| 36 | +fig.text(x=0, y=-2, text="This is @_underlined@_ text") |
| 37 | + |
| 38 | +# Use small caps |
| 39 | +fig.text(x=0, y=-3, text="T@#ext@# in S@#mall@# C@#aps@#") |
| 40 | + |
| 41 | +fig.show() |
0 commit comments