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

allow for different line widths in lines #1541

Closed
lazarusA opened this issue Jan 4, 2022 · 16 comments
Closed

allow for different line widths in lines #1541

lazarusA opened this issue Jan 4, 2022 · 16 comments

Comments

@lazarusA
Copy link
Contributor

lazarusA commented Jan 4, 2022

At the moment is possible to do several lines at once by NaN separation. Different colours also works, however passing a set of values for different line widths is not supported, as in linesegments. It would be nice to have this feature for lines, which in all my tests is the fastest one to plot thousands of lines at once.

@rveltz
Copy link

rveltz commented Jan 5, 2022

Yes, here is the MWE I have in mind:

using GLMakie
x=LinRange(0,2pi,100)
lines(x, sin.(x), linewidth = 0.19) # works
lines(x, sin.(x), linewidth = collect(x)) # does not

we get:

julia> lines(x, sin.(x), linewidth = collect(x)) # does not
Error showing value of type Makie.FigureAxisPlot:
ERROR: MethodError: Cannot `convert` an object of type Vector{Float32} to an object of type Float32

@lazarusA
Copy link
Contributor Author

lazarusA commented Jan 5, 2022

I was thinking more like:

using GLMakie
points = [Point2f(0.0, 0.0), Point2f(0.0, 1.0), Point2f(NaN, NaN),
    Point2f(1.0, 0.0), Point2f(1.0, 1.0)]
lines(points; color = [1, 1, 1, 2, 2], linewidth = 5)

this one works, but this one

points = [Point2f(0.0, 0.0), Point2f(0.0, 1.0), Point2f(NaN, NaN),
    Point2f(1.0, 0.0), Point2f(1.0, 1.0)]
lines(points; color = [1, 1, 1, 2, 2], linewidth = [2,5])
#lines(points; color = [1, 1, 1, 2, 2], linewidth = [2,2,2,5,5]) # does not work also

fails.

@SimonDanisch
Copy link
Member

Different linewidth in connected lines is a bit cumbersome... linesegments supports it though, since it doesn't need to worry about joins.

@lazarusA
Copy link
Contributor Author

lazarusA commented Jan 5, 2022

yes linesegments works at some level. In my case it crashes my Julia session for large numbers whereas lines is completely ok and fast. Bottom line, I was just wondering about the possibilities. For now I'm adding a transparency for small line widths which helps hiding a little bit those lines.

@SimonDanisch
Copy link
Member

In my case it crashes my Julia session for large numbers whereas lines is completely ok and fast

Oh thats pretty weird...Linesegments should be way more efficient...

@lazarusA
Copy link
Contributor Author

lazarusA commented Jan 5, 2022

ahh, plus I forgot to mention my lines are not straight ones (which lines can perfectly handle), which is the use case of line segments.

@rveltz
Copy link

rveltz commented Jan 5, 2022

Different linewidth in connected lines is a bit cumbersome... linesegments supports it though, since it doesn't need to worry about joins.

How come, Plots.jl provides it

@jkrumbiegel
Copy link
Member

jkrumbiegel commented Jan 5, 2022

Can you show an example of Plots.jl? I can imagine that it works if segments separated by NaNs have constant line widths, otherwise the Cairo/vector graphics limitations should apply.

@SimonDanisch
Copy link
Member

How come, Plots.jl provides it

I didn't say it's impossible 🤷 And as I said, with linesegments it's pretty easy, wouldn't be surprised if that's what plots does for different linewidths. Maybe there could be a hybrid to just start a new connected line with every linewidth change...

yes linesegments works at some level. In my case it crashes my Julia session for large numbers whereas lines is completely ok and fast

Can you open an issue with an MWE? That must be a bug!

@rveltz
Copy link

rveltz commented Jan 5, 2022

I see, should I write my own using dispatch on linewidth?

@SimonDanisch
Copy link
Member

https://bifurcationkit.github.io/BifurcationKitDocs.jl/dev/tutorials/Swift-Hohenberg1d/#d-Swift-Hohenberg-equation-(Automatic)

Hm, that does look like proper connected joints though... I guess our best bet to support that right now, would be via bands or generating our own mesh...

@SimonDanisch
Copy link
Member

Although, when I look at it again, it looks like the scatter markers hide all the joints, so can't really tell if they have proper joints... So, I guess with a scatter like that, one may get away with linesegments

@rveltz
Copy link

rveltz commented Jan 5, 2022

Plots.plot(x, sin.(x), linewidth = vcat(ones(50), 10 .*ones(50)))

Screen Shot 2022-01-05 at 12 15 29

@jkrumbiegel
Copy link
Member

Ok so you see that it's actually all linesegments, no joins. Which makes sense

@ffreyer
Copy link
Collaborator

ffreyer commented May 24, 2024

Yes, here is the MWE I have in mind:

using GLMakie
x=LinRange(0,2pi,100)
lines(x, sin.(x), linewidth = 0.19) # works
lines(x, sin.(x), linewidth = collect(x)) # does not

This worked for a while but got removed in #3558 because it's pretty complicated to deal with.

I was thinking more like:

points = [Point2f(0.0, 0.0), Point2f(0.0, 1.0), Point2f(NaN, NaN),
    Point2f(1.0, 0.0), Point2f(1.0, 1.0)]
    lines(points; color = [1, 1, 1, 2, 2], linewidth = [2,2,2,5,5])

This was effectively re-introduced in #2536. The reason I'm pointing at this instead is that the shaders consider linewidth to be constant per line segment. So without the NaN you'll end up a discontinuous connection.

I'll consider this done as the original request is fulfilled.

@ffreyer ffreyer closed this as completed May 24, 2024
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

Successfully merging a pull request may close this issue.

5 participants