Skip to content
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

Tutorial "Plotting text": Rewrite to improve structure, explain more parameters, show list input #2760

Merged
merged 57 commits into from
Apr 21, 2024
Merged
Changes from 1 commit
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
1f0c2d2
Update and Expand text tutorial
Oct 20, 2023
f670414
Merge branch 'main' into add-lists-tut-text
yvonnefroehlich Oct 22, 2023
532bcce
Merge branch 'main' into add-lists-tut-text
yvonnefroehlich Oct 25, 2023
52b8c85
Merge branch 'main' into add-lists-tut-text
yvonnefroehlich Oct 26, 2023
64996b4
Add darft of new structure
Oct 29, 2023
be7108c
Merge branch 'main' into add-lists-tut-text
yvonnefroehlich Oct 29, 2023
441d861
Use bullet points to state paramters for adjusting text label
Oct 29, 2023
fcdd028
Fix typo
Oct 29, 2023
b6e8bb8
Merge branch 'main' into add-lists-tut-text
yvonnefroehlich Nov 1, 2023
4b792a7
Update code example for optional parameters to adjust text
Nov 1, 2023
c37aac6
Improve comments
Nov 1, 2023
be3996b
Improve code example for optional parameters to adjust text label
Nov 1, 2023
97e855b
Merge branch 'main' into add-lists-tut-text
yvonnefroehlich Nov 2, 2023
299d8a2
Merge branch 'main' into add-lists-tut-text
yvonnefroehlich Nov 8, 2023
6dd12cd
Improve docs
yvonnefroehlich Nov 10, 2023
b515a1c
Merge branch 'main' into add-lists-tut-text
yvonnefroehlich Nov 10, 2023
2e35c04
Fix typo, Fix line length
yvonnefroehlich Nov 10, 2023
add8af1
Make a seperate section for 'Adding a text box'
yvonnefroehlich Nov 11, 2023
71ddc5a
Merge branch 'main' into add-lists-tut-text
yvonnefroehlich Nov 13, 2023
d54340c
Merge branch 'main' into add-lists-tut-text
yvonnefroehlich Nov 20, 2023
0a19cd0
Merge branch 'main' into add-lists-tut-text
yvonnefroehlich Dec 5, 2023
9ac3ba3
Merge branch 'main' into add-lists-tut-text
yvonnefroehlich Dec 15, 2023
706fb83
Shorten code
yvonnefroehlich Dec 21, 2023
6b19557
Merge branch 'main' into add-lists-tut-text
yvonnefroehlich Dec 21, 2023
2dcbb54
Remove un-needed import
yvonnefroehlich Dec 21, 2023
87ba574
[format-command] fixes
actions-bot Dec 21, 2023
6b5a02f
Try to remove white space
Dec 22, 2023
338bb8b
Merge branch 'main' into add-lists-tut-text
yvonnefroehlich Dec 25, 2023
d9c36d3
Merge branch 'main' into add-lists-tut-text
yvonnefroehlich Dec 26, 2023
c2c83f6
Improve argument passed to 'xshift'
yvonnefroehlich Dec 26, 2023
040c19f
Merge branch 'main' into add-lists-tut-text
yvonnefroehlich Dec 27, 2023
a011e07
Merge branch 'main' into add-lists-tut-text
yvonnefroehlich Dec 28, 2023
e0601c4
Merge branch 'main' into add-lists-tut-text
yvonnefroehlich Dec 29, 2023
8759d74
Merge branch 'main' into add-lists-tut-text
yvonnefroehlich Jan 2, 2024
3b94151
Merge branch 'main' into add-lists-tut-text
yvonnefroehlich Jan 5, 2024
1e8d070
Wrap to 88 characters
yvonnefroehlich Jan 16, 2024
946ba2a
Merge branch 'main' into add-lists-tut-text
yvonnefroehlich Jan 22, 2024
e1dc06e
Merge branch 'main' into add-lists-tut-text
yvonnefroehlich Jan 28, 2024
81a8196
Merge branch 'main' into add-lists-tut-text
yvonnefroehlich Jan 30, 2024
2c6ef52
TEST: Remove choropleth example
yvonnefroehlich Jan 31, 2024
ba521f1
TEST: Remove roads example
yvonnefroehlich Jan 31, 2024
9c58e0e
Revert "TEST: Remove choropleth example"
Feb 1, 2024
3fa7763
Revert "TEST: Remove roads example"
Feb 1, 2024
9736676
Merge branch 'main' into add-lists-tut-text
yvonnefroehlich Feb 1, 2024
0ce2204
TEST: date_time_charts - Change symbol
yvonnefroehlich Feb 5, 2024
e3afb59
Merge branch 'main' into add-lists-tut-text
yvonnefroehlich Mar 9, 2024
cf8b943
Merge branch 'main' into add-lists-tut-text
yvonnefroehlich Mar 14, 2024
7e2d975
Merge branch 'main' into add-lists-tut-text
yvonnefroehlich Apr 5, 2024
ec295eb
Follow PTH123
yvonnefroehlich Apr 5, 2024
2ece2a8
Improve documentation and comments
yvonnefroehlich Apr 11, 2024
294c8df
Merge branch 'main' into add-lists-tut-text
yvonnefroehlich Apr 11, 2024
47002ab
Remove white space
yvonnefroehlich Apr 11, 2024
3bc7d05
Add missing verb
yvonnefroehlich Apr 19, 2024
a405fd3
Remove blank line
yvonnefroehlich Apr 19, 2024
50d196f
Fix line length
yvonnefroehlich Apr 19, 2024
4ea06fb
Merge branch 'main' into add-lists-tut-text
yvonnefroehlich Apr 19, 2024
33c0d7d
Remove blank line
yvonnefroehlich Apr 20, 2024
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
Prev Previous commit
Next Next commit
Improve docs
  • Loading branch information
yvonnefroehlich committed Nov 10, 2023
commit 6dd12cd9c4e3f2152bb20834572c23239e43b23b
69 changes: 35 additions & 34 deletions examples/tutorials/basics/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
Plotting text
=============

It is often useful to add annotations to a plot. This is handled by the
:meth:`pygmt.Figure.text` method of the :class:`pygmt.Figure` class.
It is often useful to add text annotations to a plot or map. This is handled
by the :meth:`pygmt.Figure.text` method of the :class:`pygmt.Figure` class.
"""

import os
Expand All @@ -12,25 +12,25 @@
import pygmt

# %%
# Add a single text label
# -----------------------
# Adding a single text label
# --------------------------
#
# To add a single text label to a plot or map the ``text``, ``x``, and ``y``
# parameters to specify the text and position within the plot frame.
# To add a single text label to a plot the ``text`` and ``x`` and ``y``
# parameters to specify the text and position.

fig = pygmt.Figure()
fig.basemap(region=[-5, 5, -5, 5], projection="X5c", frame=True)

yvonnefroehlich marked this conversation as resolved.
Show resolved Hide resolved
yvonnefroehlich marked this conversation as resolved.
Show resolved Hide resolved
fig.text(text="My text", x=0, y=0)
fig.text(x=0, y=0, text="My text")

yvonnefroehlich marked this conversation as resolved.
Show resolved Hide resolved
fig.show()


# %%
# Adjust text labels
# ------------------
# Adjusting the text label
# ------------------------
#
# There are several optional parameters to adjust a text label:
# There are several optional parameters to adjust the text label:
#
# * ``font``: Sets the size, family/weight, and color of the font for the text.
# :gmt-docs:`PostScript Fonts Used by GMT <cookbook/postscript-fonts.html>`,
Expand All @@ -46,23 +46,24 @@
# * ``offset``: Shifts the text relatively to the reference point.
# * ``fill``: Fills the text box with a color.
# * ``pen``: Outlines the text box.
# * ``clearance``: Adds a margin in x and y directions between the text and the
# borders of the text box. Can be used to get a text box with rounded edges.
# * ``clearance``: Adds margins in x and y directions between the text and the
# outline of the text box. Can be used to get a text box with rounded edges.

fig = pygmt.Figure()

# -----------------------------------------------------------------------------
# Left: "font", "angle", and "offset" parameters
fig.basemap(region=[-5, 5, -5, 5], projection="X5c", frame=True)

# Change the font size, family/weight, color of the text
# Change font size, family/weight, color of the text
fig.text(x=0, y=3, text="my text", font="12p,Helvetica-Bold,blue")

# Rotate the text by 30 degrees counter-clockwise from the horizontal
fig.text(x=0, y=0, text="my text", angle=30)

# Shift the text relatively to the x and y positions by 1 centimeter to the
# right (positive x direction) and 0.5 centimeters down (negative y direction)
# Shift the text relatively to the position given via the x and y parameters
# by 1 centimeter to the right (positive x direction) and 0.5 centimeters down
# (negative y direction)
fig.plot(x=0, y=-3, style="s0.2c", fill="darkorange", pen="0.7p,darkgray")
fig.text(x=0, y=-3, text="my text")
fig.text(x=0, y=-3, text="my text", offset="1c/-0.5c")
Expand All @@ -82,8 +83,8 @@
pen="0.7p,darkgray",
)

# Plot text at the same x and y positions as the markers
# but with varying justifications
# Plot text labels at the x and y positions of the markers
# while using varying justifications
fig.text(x=-0.5, y=0.5, text="TL", justify="TL") # TopLeft
fig.text(x=0, y=0.5, text="TM", justify="TC") # TopCenter
fig.text(x=0.5, y=0.5, text="TR", justify="TR") # TopRight
Expand All @@ -103,25 +104,25 @@
# Add a box with a fill in green color
fig.text(x=0, y=3, text="My text", fill="green")

# Add box with a seagreen, 1 point thick, solid outline
# Add box with a seagreen, 1-point thick, solid outline
fig.text(x=0, y=1, text="My text", pen="1p,seagreen,solid")

# Add a margin between the text and border of the text box of 0.1 centimeters
# in x direction and 0.2 centimeters in y direction
fig.text(x=0, y=-1, text="My text", pen="1p,seagreen,dashed", clearance="0.2c/0.2c")
# Add margins between the text and the outline of the text box of 0.1
# centimeters in x direction and 0.2 centimeters in y direction
fig.text(x=0, y=-1, text="My text", pen="1p,seagreen,dashed", clearance="0.1c/0.2c")

# Get rounded edges by appending "+tO" to the "clearance" parameter
# Get rounded edges by passing "+tO" to the "clearance" parameter
fig.text(x=0, y=-3, text="My text", pen="1p,seagreen,solid", clearance="0.2c/0.2c+tO")

fig.show()


# %%
# Plotting text with individual configurations
# --------------------------------------------
# Adding multiple text labels with individual configurations
# ----------------------------------------------------------
#
# To add text with individual ``font``, ``angle``, and ``justify`` one can
# provide lists with the corresponding arguments.
# To add mulitple text labels with individual ``font``, ``angle``, and ``justify``
# one can provide lists with the corresponding arguments.

fig = pygmt.Figure()
fig.basemap(region=[-5, 5, -5, 5], projection="X5c", frame=True)
Expand All @@ -143,12 +144,12 @@


# %%
# Use an external txt file
# ------------------------
# Using an external input file
# ----------------------------
#
# It is also possible to add text labels via an external text file containing
# It is also possible to add text labels via an external input file containing
# ``x``, ``y``, and ``text`` columns. Addionaly, columns to set the ``angle``,
# ``front``, and ``justify`` parameters can be provided. Here we give a
# ``front``, and ``justify`` parameters can be provided. Here, we give a
# complete example.

fig = pygmt.Figure()
Expand Down Expand Up @@ -178,8 +179,8 @@


# %%
# The position parameter
# ----------------------
# Using the position parameter
# ----------------------------
#
# Instead of using ``x`` and ``y``, the ``position`` parameter can be
# specified to set the reference point for the text on the plot.
Expand Down Expand Up @@ -208,7 +209,7 @@
fig.shift_origin(xshift="+w1c")

# -----------------------------------------------------------------------------
# Right: Add a text label out of the plot or map frame
# Right: Add a text label outside of the plot or map frame

# Define region limits
lon_min = -30
Expand All @@ -234,7 +235,7 @@
position="TC",
justify="MC",
offset="0c/0.2c",
no_clip=True, # Allow plotting out of map or plot frame
no_clip=True, # Allow plotting outside of the map or plot frame
)

fig.show()
Expand Down
Loading