Skip to content

Commit de00b71

Browse files
Add gallery example for plotting connection lines ("connection" parameter of Figure.plot) (#2999)
1 parent 1509a02 commit de00b71

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
"""
2+
Connection lines
3+
================
4+
5+
The ``connection`` parameter of the :meth:`pygmt.Figure.plot` method allows to plot
6+
connection lines between a set of data points. Width, color, and style of the lines
7+
can be adjusted via the ``pen`` parameter. The data points must be plotted separately
8+
using the ``style`` parameter, with adjustments for the symbol fill and outline via
9+
the ``fill`` and ``pen`` parameters, respectively.
10+
"""
11+
12+
# %%
13+
import pygmt
14+
15+
# Set up same sample data
16+
x = [2.2, 3.3, -3.1, -3.7, -0.1]
17+
y = [1.8, -1.2, -0.9, -4.5, 4.5]
18+
19+
# Create new Figure instance
20+
fig = pygmt.Figure()
21+
22+
# -----------------------------------------------------------------------------
23+
# Left: record order
24+
fig.basemap(region=[-5, 5, -5, 5], projection="X6c", frame=["WSne", "af"])
25+
26+
# Connect data points based on the record order [Default connection=None]
27+
fig.plot(x=x, y=y, pen="1.5p,dodgerblue")
28+
# Plot data points
29+
fig.plot(x=x, y=y, style="c0.2c", fill="green3", pen="1.5p")
30+
31+
fig.shift_origin(xshift="w+0.5c")
32+
33+
# -----------------------------------------------------------------------------
34+
# Middle: network
35+
fig.basemap(region=[-5, 5, -5, 5], projection="X6c", frame=["wSne", "af"])
36+
37+
# Connect data points as network
38+
fig.plot(x=x, y=y, pen="1.5p,dodgerblue", connection="n")
39+
# Plot data points
40+
fig.plot(x=x, y=y, style="c0.2c", fill="green3", pen="1.5p")
41+
42+
fig.shift_origin(xshift="w+0.5c")
43+
44+
# -----------------------------------------------------------------------------
45+
# Right: reference point
46+
fig.basemap(region=[-5, 5, -5, 5], projection="X6c", frame=["wSne", "af"])
47+
48+
# Connect data points with the reference point (0,0)
49+
fig.plot(x=x, y=y, pen="1.5p,dodgerblue", connection="p0/0")
50+
# Plot data points
51+
fig.plot(x=x, y=y, style="c0.2c", fill="green3", pen="1.5p")
52+
# Plot reference point
53+
fig.plot(x=0, y=0, style="s0.3c", fill="gold", pen="1.5p")
54+
55+
fig.show()

0 commit comments

Comments
 (0)