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

Add gallery example for plotting connection lines ("connection" parameter of Figure.plot) #2999

Merged
merged 11 commits into from
Jan 19, 2024
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_cords = [2.2, 3.3, -3.1, -3.7, -0.1]
y_cords = [1.8, -1.2, -0.9, -4.5, 4.5]
yvonnefroehlich marked this conversation as resolved.
Show resolved Hide resolved

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

# -----------------------------------------------------------------------------
# Left: record order
fig.basemap(region=[-5, 5, -5, 5], projection="X10c", frame=["WSne", "a1"])
yvonnefroehlich marked this conversation as resolved.
Show resolved Hide resolved

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

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

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

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

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

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

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

fig.show()
Loading