Skip to content

Commit f8e3f27

Browse files
Add a gallery example of setting line colors with a custom CPT (#774)
Co-authored-by: Dongdong Tian <[email protected]>
1 parent 4b630b3 commit f8e3f27

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
"""
2+
Line colors with a custom CPT
3+
-----------------------------
4+
5+
The color of the lines made by :meth:`pygmt.Figure.plot` can be set according to a
6+
custom CPT and assigned with the ``pen`` argument.
7+
8+
The custom CPT can be used by setting the plot command's ``cmap`` argument to ``True``. The
9+
``zvalue`` argument sets the z-value (color) to be used from the custom CPT, and the line
10+
color is set as the z-value by using **+z** when setting the ``pen`` color.
11+
12+
"""
13+
14+
import numpy as np
15+
import pygmt
16+
17+
# Create a list of values between 20 and 30 with at 0.2 intervals
18+
x = np.arange(start=20, stop=30, step=0.2)
19+
20+
fig = pygmt.Figure()
21+
fig.basemap(frame=["WSne", "af"], region=[20, 30, -10, 10])
22+
23+
# Create a custom CPT with the batlow CPT and 10 discrete z-values (colors)
24+
pygmt.makecpt(cmap="batlow", series=[0, 10, 1])
25+
26+
# Plot 10 lines and set a different z-value for each line
27+
for zvalue in range(0, 10):
28+
y = zvalue * np.sin(x)
29+
fig.plot(x=x, y=y, cmap=True, zvalue=zvalue, pen="thick,+z,-")
30+
# Color bar to show the custom CPT and the associated z-values
31+
fig.colorbar()
32+
fig.show()

0 commit comments

Comments
 (0)