MakieOrg / Makie.jl

Interactive data visualizations and plotting in Julia
https://docs.makie.org/stable
MIT License
2.35k stars 291 forks source link

Missing line segments in PolarAxis #3927

Open pzabka opened 1 month ago

pzabka commented 1 month ago

When creating lines in PolarAxis, some line segments (around r=0 or theta=2pi) are missing.

MWE:

k = 50
fig = Figure()
ax = PolarAxis(fig[1, 1]; radius_at_origin=0)
lines!(ax, 0:pi/k:2*pi, cos; linewidth=5)
fig

It should be a full circle, but I got this instead:

fig1_bug

When changing the parametr k, the effect may vary.

Tested with: GLMakie v0.10.0 (Makie v0.21.0, Makiecore v0.8.0) CairoMakie v0.12.0 (Makie v0.21.0, Makiecore v0.8.0) GLMakie v0.9.10 (Makie v0.20.9, MakieCore v0.7.3) CairoMakie v0.11.10 (Makie v0.20.9, MakieCore v0.7.3)

ffreyer commented 1 month ago

The gap at r = 0 happens because by default PolarAxis removes points with negative radius. You can turn that off by setting clip_r = false. The gap at r = 1 happens because the range doesn't include 2pi. With clip_r = false you end up drawing the circle twice you won't see the missing r = 1 section anymore.

asinghvi17 commented 1 month ago

Should we clamp r to zero instead of clipping by default? Seems like that would be less surprising.

jkrumbiegel commented 1 month ago

I'm wondering why r = 0 is a negative radius

ffreyer commented 1 month ago

It's not https://github.com/MakieOrg/Makie.jl/blob/d57e9d3f5f376dbe52b9d6a0f0c000dcb734a0d8/src/layouting/transformation.jl#L477-L479 It's just that the next point in the line is at a negative radius.

I think regardless of what we do by default it's going to have some downsides.

Related: https://github.com/MakieOrg/Makie.jl/pull/3381 https://github.com/MakieOrg/Makie.jl/issues/3375

pzabka commented 1 month ago

Thank you for a great explanation.

Out of curiosity, I have tried Plots.jl and Matlab and in both cases the default behaviour is radius_at_origin=0, clip_r = false However, I agree that such a result is quite misleading, and the current Makie behaviour feels better. It is just confusing that the line is not going to r=0, leaving the plot area.