8000 `voronoiplot` with a matrix creates a 3D plot · Issue #4335 · MakieOrg/Makie.jl · GitHub
[go: up one dir, main page]

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

voronoiplot with a matrix creates a 3D plot #4335

Closed
2 tasks done
DanielVandH opened this issue Sep 8, 2024 · 8 comments · Fixed by #4349
Closed
2 tasks done

voronoiplot with a matrix creates a 3D plot #4335

DanielVandH opened this issue Sep 8, 2024 · 8 comments · Fixed by #4349
Labels
bug conversions Mainly `convert_arguments` Makie Backend independent issues (Makie core)

Comments

@DanielVandH
Copy link
Contributor
DanielVandH commented Sep 8, 2024

Using voronoiplot with a matrix creates a 3D plot. The 2D tessellation shown is incorrect.

julia> using CairoMakie

julia> pts = rand(2, 5);

julia> voronoiplot(pts)

image

  • what version of Makie are you running? (]st -m Makie)
(jl_SxZtlw) pkg> st -m Makie
Status `C:\Users\danjv\AppData\Local\Temp\jl_SxZtlw\Manifest.toml`
  [ee78f7c6] Makie v0.21.9
  • can you reproduce the bug with a fresh environment ? (]activate --temp; add Makie)
@DanielVandH DanielVandH added the bug label Sep 8, 2024
@asinghvi17 asinghvi17 added the Makie Backend independent issues (Makie core) label Sep 9, 2024
@asinghvi17
Copy link
Member

It looks like an issue in convert_arguments for voronoiplot:

julia> Makie.convert_arguments(Makie.Voronoiplot, rand(2, 5))
(Point{3, Float64}[[1.0, 1.0, 0.5306268315612478], [2.0, 1.0, 0.3057094707535708], [1.0, 2.0, 0.0386010373499962], [2.0, 2.0, 0.8346339986368071], [1.0, 3.0, 0.6964743865655425], [2.0, 3.0, 0.10789307734909603], [1.0, 4.0, 0.7161808096490242], [2.0, 4.0, 0.6060931129469319], [1.0, 5.0, 0.32697816623710696], [2.0, 5.0, 0.3249893139346661]],)

The offending convert is:

# For heatmap-like inputs
function convert_arguments(::Type{<:Voronoiplot}, mat::AbstractMatrix)
    return convert_arguments(PointBased(), axes(mat, 1), axes(mat, 2), mat)
end

I'm not sure what the idea was here - were the mat values supposed to be z values?

< 8000 div class="js-timeline-item js-timeline-progressive-focus-container" data-gid="IC_kwDOBj86C86LSlgV">
@asinghvi17
Copy link
Member

Also, is this what you were aiming for?

voronoiplot(rand(Point2f, 5))

display

@DanielVandH
Copy link
Contributor Author
DanielVandH commented Sep 9, 2024

That is what I was looking for, yeah. It should be the same as plotting voronoiplot(voronoi(triangulate(rand(2, 5)))).

I'm not sure exactly the intention behind the convert_arguments is. I don't believe I wrote that one (but if I did it's probably me having no idea anyway). I'm guessing the idea was that, like heatmap IIRC a matrix of numbers gets interpreted as z-values with the x and y coordinates being the axes. I think maybe @ffreyer wrote that?

@asinghvi17 asinghvi17 added the conversions Mainly `convert_arguments` label Sep 9, 2024
@asinghvi17
Copy link
Member

It might be easier then to declare voronoiplot a point-based plot? Not sure what the z values are intended to do there to be honest.

@DanielVandH
Copy link
Contributor Author
8000

Looking back at the original PR, I think the intention was that it serves as a sort of nonlinear heat map

@asinghvi17
Copy link
Member
asinghvi17 commented Sep 9, 2024

Aha, ok. It is doing that - see:

voronoiplot(reshape(1:8, (4, 2)); axis = (; type=Axis))
Screenshot 2024-09-09 at 2 39 06 PM

so I think we just want this to be forced to a 2d axis by default?

The other question is - do you even need a 2d nonlinear heatmap? surface and heatmap both work on rectilinear grids (and surface even works on nonlinear grids, and can be uninterpolated):

hello

There are also no examples of heatmap-like behaviour in the docs, so we should add that if nothing else.

@DanielVandH
Copy link
Contributor Author
DanielVandH commented Sep 9, 2024

Since @ffreyer (I think) was the one to implement this behaviour, I'll leave that to him. I personally forgot that was originally setup in the original PR until making this issue and was surprised that the behaviour was different to triplot (maybe because I just use both frequently, though). I have no need for such a heatmap myself.

@ffreyer
Copy link
Collaborator
ffreyer commented Sep 10, 2024

Yea I think nonlinear heatmaps were my reason for it.

The other question is - do you even need a 2d nonlinear heatmap? surface and heatmap both work on rectilinear grids (and surface even works on nonlinear grids, and can be uninterpolated):

Didn't know un-interpolated surface works, but it always uses quads while voronoi doesn't so I think there is still a use. E.g.:

begin
    v1 = Vec2f(1, 0)
    v2 = Vec2f(cosd(60), sind(60))
    ps = Point2f[x * v1 + y * v2 for x in 1:10, y in 1:10]
    xs = first.(ps)
    ys = last.(ps)
    cs = rand(size(ps)...)

8D0D
    f, a, p = surface(xs, ys, zeros(size(ps)), color = cs, interpolate = false)
    a = Axis(f[1, 2])
    # voronoiplot!(a, ps[:], color = cs)
    voronoiplot!(a, xs, ys, cs)
    f
end

Screenshot 2024-09-10 015722

Maybe it's a bit pointless to have matrix conversions but I think more is better there. So I'd say just add a preferred_axis_type(::VoronoiPlot) = Axis

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug conversions Mainly `convert_arguments` Makie Backend independent issues (Makie core)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants
0