Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some vectors lost head #3282

Closed
sungho91 opened this issue Jun 3, 2024 · 6 comments
Closed

Some vectors lost head #3282

sungho91 opened this issue Jun 3, 2024 · 6 comments
Labels
bug Something isn't working

Comments

@sungho91
Copy link

sungho91 commented Jun 3, 2024

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

vel_1deg_NNR

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
@sungho91 sungho91 added the bug Something isn't working label Jun 3, 2024
Copy link

welcome bot commented Jun 3, 2024

👋 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.

@yvonnefroehlich
Copy link
Member

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()

arrows_heads_disapear

@sungho91
Copy link
Author

sungho91 commented Jun 3, 2024

Hi @yvonnefroehlich

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?

Archive.zip

@seisman
Copy link
Member

seisman commented Jun 4, 2024

I think you need to use +n in the style parameter. See https://docs.generic-mapping-tools.org/dev/plot.html#vector-attributes

@yvonnefroehlich
Copy link
Member

I think you need to use +n in the style 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)

arrows_heads_disapear_back_with_n

@sungho91
Copy link
Author

sungho91 commented Jun 4, 2024

This is really helpful. It just occurred to me. I just adjusted very small size lengths to a certain magnitude.
FYI, it also works.

vel_1deg_NNR

@sungho91 sungho91 closed this as completed Jun 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants