Skip to content

Commit

Permalink
Add gallery example for plotting connection lines ("connection" param…
Browse files Browse the repository at this point in the history
…eter of Figure.plot) (#2999)
  • Loading branch information
yvonnefroehlich authored Jan 19, 2024
1 parent 1509a02 commit de00b71
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions examples/gallery/lines/connection_lines.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
"""
Connection lines
================
The ``connection`` parameter of the :meth:`pygmt.Figure.plot` method allows to plot
connection lines between a set of data points. Width, color, and style of the lines
can be adjusted via the ``pen`` parameter. The data points must be plotted separately
using the ``style`` parameter, with adjustments for the symbol fill and outline via
the ``fill`` and ``pen`` parameters, respectively.
"""

# %%
import pygmt

# Set up same sample data
x = [2.2, 3.3, -3.1, -3.7, -0.1]
y = [1.8, -1.2, -0.9, -4.5, 4.5]

# Create new Figure instance
fig = pygmt.Figure()

# -----------------------------------------------------------------------------
# Left: record order
fig.basemap(region=[-5, 5, -5, 5], projection="X6c", frame=["WSne", "af"])

# Connect data points based on the record order [Default connection=None]
fig.plot(x=x, y=y, pen="1.5p,dodgerblue")
# Plot data points
fig.plot(x=x, y=y, style="c0.2c", fill="green3", pen="1.5p")

fig.shift_origin(xshift="w+0.5c")

# -----------------------------------------------------------------------------
# Middle: network
fig.basemap(region=[-5, 5, -5, 5], projection="X6c", frame=["wSne", "af"])

# Connect data points as network
fig.plot(x=x, y=y, pen="1.5p,dodgerblue", connection="n")
# Plot data points
fig.plot(x=x, y=y, style="c0.2c", fill="green3", pen="1.5p")

fig.shift_origin(xshift="w+0.5c")

# -----------------------------------------------------------------------------
# Right: reference point
fig.basemap(region=[-5, 5, -5, 5], projection="X6c", frame=["wSne", "af"])

# Connect data points with the reference point (0,0)
fig.plot(x=x, y=y, pen="1.5p,dodgerblue", connection="p0/0")
# Plot data points
fig.plot(x=x, y=y, style="c0.2c", fill="green3", pen="1.5p")
# Plot reference point
fig.plot(x=0, y=0, style="s0.3c", fill="gold", pen="1.5p")

fig.show()

0 comments on commit de00b71

Please sign in to comment.