Some vectors lost head
sungho91 opened this issue · 6 comments
Description of the problem
Hi
All vectors should have a head but some of them don't have (orange-dotted box in att.).
How can I fix them?
Best,
Sungho
Minimal Complete Verifiable Example
# Define a scaling factor to scale the vectors appropriately
scaling_factor = 0.1 # Vector length
arrow_width = 0.01 # Arrowhead width
arrow_length = 0.1 # Arrowhead length
freq = 64
fig = pygmt.Figure()
fig.coast(region="g", projection="N12", land="gray", frame="af")
fig.plot(
region="g",
projection="N12",
x=longitude_gps.flatten()[::freq],
y=latitude_gps.flatten()[::freq],
direction=[gps_velocity_direction.flatten()[::freq], 0.01*gps_velocity_length.flatten()[::freq]],
style=f'v{scaling_factor}c+e{arrow_width}c+h{arrow_length}c',
# style=f'v0.2+e+h0.3',
pen="0.3p,red3",
color="red3",
)
fig.savefig('vel_1deg_NNR.png')
fig.show()
Full error message
No response
System information
I tested it on M1 macbook and Ubuntu 22.04
👋 Thanks for opening your first issue here! Please make sure you filled out the template with as much detail as possible. You might also want to take a look at our contributing guidelines and code of conduct.
Hello @sungho91,
As we do not have your input data, we cannot run your script.
However, I think the vectors within the orange-dashed box are drawn without heads because the vector length is too short relatively to the size of the heads. Please find below a general code example showing this:
import numpy as np
import pygmt
x = np.linspace(0.2, 0.2, 6) # x vector coordinates
y = np.linspace(-2, 2, 6) # y vector coordinates
direction = np.zeros(x.shape) # direction of vectors
length = np.linspace(0.1, 1.4, 6) # length of vectors
fig = pygmt.Figure()
fig.basemap(region=[0, 10, -2.5, 2.5], projection="X5c/3c", frame=0)
# Plot Cartesian vectors with different lengths and diffent head sizes
fig.plot(x=x, y=y, style="v0.4c+e", direction=[direction, length])
fig.plot(x=x+3.3, y=y, style="v0.2c+e", direction=[direction, length])
fig.plot(x=x+6.6, y=y, style="v0.1c+e", direction=[direction, length])
fig.show()
Thank you for your comment. I've attached my files to this.
So, if the length of velocity is too small, there is no way to plot them with a head?
I think you need to use +n
in the style
parameter. See https://docs.generic-mapping-tools.org/dev/plot.html#vector-attributes
I think you need to use
+n
in thestyle
parameter. See https://docs.generic-mapping-tools.org/dev/plot.html#vector-attributes
I just modified my code example to compare the results without (black) and with (red) using +n
:
# Modified from https://www.pygmt.org/dev/gallery/lines/vector_styles.html#sphx-glr-gallery-lines-vector-styles-py
# Last access 2024/06/03
import numpy as np
import pygmt
x = np.linspace(0.4, 0.4, 4) # x vector coordinates
y = np.linspace(-1, 1, 4) # y vector coordinates
direction = np.zeros(x.shape) # direction of vectors
length = np.linspace(0.1, 0.5, 4) # length of vectors
fig = pygmt.Figure()
fig.basemap(region=[0, 3, -1.5, 1.5], projection="X3c/2c", frame=0)
for keep_head in ["", "+n"]:
match keep_head:
case "": pen = "0.7p,black"
case "+n": pen = "0.2p,red"
# Plot Cartesian vectors with different lengths and diffent head sizes
fig.plot(x=x, y=y, style=f"v0.4c+e{keep_head}", pen=pen, direction=[direction, length])
fig.plot(x=x+1, y=y, style=f"v0.2c+e{keep_head}", pen=pen, direction=[direction, length])
fig.plot(x=x+2, y=y, style=f"v0.1c+e{keep_head}", pen=pen, direction=[direction, length])
fig.show(dpi=720)