Skip to content

Commit 1a56da1

Browse files
authored
Add an example for different line styles (#604)
1 parent 9fa9185 commit 1a56da1

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

doc/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
"gallery_dirs": ["gallery", "tutorials", "projections"],
6161
"subsection_order": ExplicitOrder(
6262
[
63+
"../examples/gallery/line",
6364
"../examples/gallery/coast",
6465
"../examples/gallery/plot",
6566
"../examples/gallery/grid",

examples/gallery/line/README.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Lines
2+
-----

examples/gallery/line/linestyles.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
"""
2+
Line styles
3+
-----------
4+
5+
The :meth:`pygmt.Figure.plot` method can plot lines in different styles.
6+
The default line style is a 0.25-point wide, black, solid line, and can be
7+
customized via the ``pen`` argument.
8+
9+
A *pen* in GMT has three attributes: *width*, *color*, and *style*.
10+
The *style* attribute controls the appearance of the line.
11+
Giving “dotted” or “.” yields a dotted line, whereas a dashed pen is requested
12+
with “dashed” or “-”. Also combinations of dots and dashes, like “.-” for a
13+
dot-dashed line, are allowed.
14+
15+
For more advanced *pen* attributes, see the GMT cookbook
16+
:gmt-docs:`cookbook/features.html#wpen-attrib`.
17+
18+
"""
19+
20+
import numpy as np
21+
import pygmt
22+
23+
# Generate a sample line for plotting
24+
x = np.linspace(0, 10, 500)
25+
y = np.sin(x)
26+
27+
fig = pygmt.Figure()
28+
fig.basemap(region=[0, 10, -3, 3], projection="X15c/8c", frame=["xaf", "yaf", "WSrt"])
29+
30+
# Plot the line using the default line style
31+
fig.plot(x=x, y=y)
32+
33+
# Plot the lines using different line styles
34+
fig.plot(x=x, y=y + 1.5, pen="1p,red,-")
35+
fig.plot(x=x, y=y + 1.0, pen="2p,blue,.")
36+
fig.plot(x=x, y=y + 0.5, pen="1p,red,-.")
37+
38+
fig.plot(x=x, y=y - 0.5, pen="2p,blue,..-")
39+
fig.plot(x=x, y=y - 1.0, pen="3p,tomato,--.")
40+
fig.plot(x=x, y=y - 1.5, pen="3p,tomato,4_2:2p")
41+
42+
fig.show()

0 commit comments

Comments
 (0)