Actually there are two options for what can be colored:
- the fill of the vector head
- the line and outline of the vector
Just played around with some codes from the PyGMT Tutorial at Plotting vectors — PyGMT
import pygmt
import numpy as np
vector_num = 5
radius = 3 - (0.5 * np.arange(0, vector_num))
startdir = np.full(vector_num, 90)
stopdir = 180 + (50 * np.arange(0, vector_num))
color = np.arange(0, vector_num)
# -----------------------------------------------------------------------------
# (I) Color-coding of the vector head
# Quantity for color coding must be in the third coloum of the input data
data = np.column_stack(
[np.full(vector_num, 0), np.full(vector_num, 0), color, radius, startdir, stopdir]
)
fig = pygmt.Figure()
fig.basemap(region=[-5, 5, -5, 5], projection="X10c", frame="ag")
pygmt.makecpt(cmap="batlow", series=[0, vector_num, 1])
fig.plot(data=data, style="m1c+ea", fill="+z", cmap=True)
fig.show()
# -----------------------------------------------------------------------------
# (II) Color-coding of line and outline of the vector
# Need to loop over all vectors (line)
# See also https://www.pygmt.org/v0.14.2/gallery/lines/line_custom_cpt.html
# Last access: 2025/02/20
data = np.column_stack(
[np.full(vector_num, 0), np.full(vector_num, 0), radius, startdir, stopdir]
)
fig = pygmt.Figure()
fig.basemap(region=[-5, 5, -5, 5], projection="X10c", frame="ag")
pygmt.makecpt(cmap="batlow", series=[0, vector_num, 1])
for i_vector in range(len(data)):
fig.plot(
data=[data[i_vector]], style="m1c+ea", zvalue=color[i_vector], pen="2p,+z", cmap=True,
)
fig.show()
(I) vector head
(II) line and outline