Using a color map on arrow plotting

Hello, I have been trying to make a pygmt plot with colored arrows according to length. I have tried adding cmap=True, fill=length to my plot call, but the function is not interpreting it as I expected and the arrows come out without coloring and all pointing in the same direction. I have seen it done in gmt with grdvector, so a way to translate my workflow to use it would be helpful too, but I worry I won’t be able to plot a grid below it as I’m doing now.

Thank you very much in advance!

Hi @Feva67,

It makes helping much easier, in case you can post a complete working code example (including the needed input data).

In principle, for color-coding symbols the desired quantity has to be in the thirth column of the input data.

For vectors, please note, that the synthax has changed between GMT 4 and GMT 5 (plot — GMT 6.6.0 documentation). For the new vector definition, the stem is no longer considered as polygon (see also parts of How to draw double-headed arrows with hollow and solid heads in pygmt?). However, the GMT 4 synthax is still supported, and users can do something like this:

# %%
import pygmt

# Set up example data for plotting arrows
# x, y, quantity which should be used for the color-coding, direction, length
data = data=[
    [-3, 0, -3, 45, 0.2],
    [-1, 0, -1, 15, 0.5],
    [1, 0, 1, 70, 0.8],
    [3, 0, 3, -30, 1],
]

fig = pygmt.Figure()
fig.basemap(region=[-5, 5, -1, 1], projection="X10c/2c", frame="a1g1")

pygmt.makecpt(cmap="batlow", series=[-4, 4])
fig.plot(
    data=data,
    # GMT4 synthax tailwidth/headlength/halfheadwidth
    style="vt0.06c/0.15c/0.1c",
    pen="0.01p",
    cmap=True,

)
fig.colorbar(frame=True)

fig.show()


For color-coding appliled to pen (to fill), please see the example Line colors with a custom CPT — PyGMT.

1 Like

Thank you! This worked perfectly, although I wonder why the newer syntax does not translate to it (as in separately listing x, y, direction, fill)