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

[FR] Ability to resize the arrow heads in e.g. quiver plots #4881

Open
TorkelE opened this issue Jan 28, 2024 · 7 comments
Open

[FR] Ability to resize the arrow heads in e.g. quiver plots #4881

TorkelE opened this issue Jan 28, 2024 · 7 comments

Comments

@TorkelE
Copy link

TorkelE commented Jan 28, 2024

I have been trying to figure out how to do this (trying tons of various options), but currently does not seem to be possible in Plots.

It would be useful to be able to resize the arrowheads in e.g. quiver plots. E.g. for

using Plots
xs = vcat([fill(i,10) for i in 1:10]...)
ys = vcat(fill(1:10,10)...)
dxs = (0.8 .- rand(100)) ./2
dys = (0.6 .- rand(100)) ./2
quiver(xs, ys; quiver=(dxs,dys))

image

Especially when the arrow lines are small, the arrowheads looks really weird and ugly.

@j-adel
Copy link

j-adel commented Dec 15, 2024

I really suggest this arrow!() function. This issue has been there for over 7 years. I think it's time...

@BeastyBlacksmith
Copy link
Member

You are welcome to open a PR 🙂

@j-adel
Copy link

j-adel commented Dec 16, 2024

You are welcome to open a PR 🙂

It seems to me that function quiver_using_arrows(plotattributes::AKW) is already designed to have scaling arrow heads. I'm not sure if there's something preventing its use or if there's a way for the user to select it.

@BeastyBlacksmith
Copy link
Member

True, but that is only used, if the backend supports the :arrow attribute

@recipe function f(::Type{Val{:quiver}}, x, y, z)  # COV_EXCL_LINE
    @nospecialize
    if :arrow in supported_attrs()
        quiver_using_arrows(plotattributes)
    else
        quiver_using_hack(plotattributes)
    end
    ()
end

which GR currently does not:

const _gr_attrs = PlotsBase.merge_with_base_supported([

That is why it uses the other implementation

@j-adel
Copy link

j-adel commented Dec 17, 2024

The problem isn't in quiver_using_hack (which is actually not triggered in GR. In fact, hack has scaling arrow heads:
image
It's the quiver_using_arrows() that's problematic. But I really don't understand the library structure to see where the line vectors are being computed.

@BeastyBlacksmith
Copy link
Member

BeastyBlacksmith commented Dec 17, 2024

Okay, so the intended API from the Plots side is to be able to call e.g.

quiver(xs, ys; quiver=(dxs,dys), arrow = arrow(0.5))
quiver(xs, ys; quiver=(dxs,dys), arrow = arrow(0.5, 0.3))

To set the style of the arrows.

The arrow properties are specified by an Arrow stuct, defined here:

struct Arrow

However, the GR backend currently only uses arrow.side and arrow.style when drawing arrows, like here:

arrowside, arrowstyle = if (arrow = series[:arrow]) isa Arrow

So, IMO the backend would need to be changed to take arrow.headlength and arrow.headwidth into account.

@j-adel
Copy link

j-adel commented Dec 17, 2024

I see. But it seems like the function utilizes GR.drawarrow() which doesn't take more than the coordinates, the direction, and a preset style.

https://github.com/JuliaPlots/Plots.jl/blob/da79316e5bd768e417f65f344b7d749e41bbb0be/PlotsBase/ext/GRExt.jl#L391:392

From the GR backend https://gr-framework.org/_modules/gr.html#setarrowstyle, it seems like you can't set the arrow head to automatically scale. But there is also a setarrowsize(size). Maybe that's worth trying? I'm sorry but I'm busy these couple of weeks so I can't dive into GR backend at this point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants