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

Contour limits changed from 0.19.9 to 0.19.10 #3259

Closed
jkrumbiegel opened this issue Sep 27, 2023 · 6 comments
Closed

Contour limits changed from 0.19.9 to 0.19.10 #3259

jkrumbiegel opened this issue Sep 27, 2023 · 6 comments
Labels

Comments

@jkrumbiegel
Copy link
Member

@ffreyer I don't quite understand it yet but assume it's connected with #3227

MWE:

In 0.19.9, this contour plot has quite a lot of white space around it. Interestingly, the two different data_limits calls I @show have different return values. The latter is tighter. But I have already deleted the text child plot here which was introduced a while ago when labels were added.

using CairoMakie
using Makie.KernelDensity
using Random

Random.seed!(123)

x = randn(100)
y = randn(100)
k = kde(hcat(x, y))

f = Figure()
ax = Axis(f[1, 1])

c = contour!(ax, k.x, k.y, k.density)
popfirst!(c.plots)

@show Makie.data_limits(c)
@show Makie.data_limits(c.plots[1])

f
Makie.data_limits(c) = GeometryBasics.HyperRectangle{3, Float32}(Float32[-3.858967, -3.973673, 0.0], Float32[7.2212353, 8.19762, 0.0])
Makie.data_limits(c.plots[1]) = GeometryBasics.HyperRectangle{3, Float32}(Float32[-1.9766064, -1.5087711, 0.0], Float32[3.4296885, 3.5192566, 0.0])

This is the output image:

image

When I define this method and don't delete the text plot

Makie.data_limits(c::Contour) = data_limits(c.plots[2])

I get this output plot:

image

Which corresponds to the tighter limits.

On 0.19.10 I get this output

Makie.data_limits(c) = GeometryBasics.HyperRectangle{3, Float32}(Float32[-1.9766064, -1.5087711, 0.0], Float32[3.4296885, 3.5192566, 0.0])
Makie.data_limits(c.plots[1]) = GeometryBasics.HyperRectangle{3, Float32}(Float32[-1.9766064, -1.5087711, 0.0], Float32[3.4296885, 3.5192566, 0.0])

image

Maybe the new behavior is just a bug fix, and it seems so from the look of it because the limits are tighter around the actually visible lines. But I still want to understand why the old one had a different result, even when excluding the text.

@ffreyer
Copy link
Collaborator

ffreyer commented Sep 27, 2023

There is still a point_iterator overwrite there which probably gets skipped now:

function point_iterator(x::Contour{<: Tuple{X, Y, Z}}) where {X, Y, Z}
axes = (x[1], x[2])
extremata = map(extremato_value, axes)
minpoint = Point2f(first.(extremata)...)
widths = last.(extremata) .- first.(extremata)
rect = Rect2f(minpoint, Vec2f(widths))
return unique(decompose(Point, rect))
end

Or is that only 3d?

@ffreyer
Copy link
Collaborator

ffreyer commented Sep 27, 2023

Yea, calling that reports the old results:

julia> Rect2f(Makie.point_iterator(c))
GeometryBasics.HyperRectangle{2, Float32}(Float32[-3.858967, -3.973673], Float32[7.2212353, 8.19762])

which should be the limits of the raw data input, rather than the generated lines.

I would say the new limits are better and we should just keep them. (Though they are probably a bit more expensive because there are probably more points in the lines than the input?)

@jkrumbiegel
Copy link
Member Author

Yes I think they're better, too. Ok then I understand where the difference comes from. Still a bit weird that the result is different depending on whether a plot is nested or not, but maybe data_limits is not actually the correct entrypoint into this

@ffreyer
Copy link
Collaborator

ffreyer commented Sep 27, 2023

Yes I think they're better, too. Ok then I understand where the difference comes from. Still a bit weird that the result is different depending on whether a plot is nested or not, but maybe data_limits is not actually the correct entrypoint into this

The old path was data_limits(parent_plot) -> point_iterator(parent_plot) which uses the method I linked to above, i.e. it looks at the input data to figure out limits. Here you get different results from parent vs nested because you're looking at different data.

The new path is data_limits(parent_plot) -> data_limits(child_plot) -> point_iterator(child_plot) which grabs the limits from the processed data, the lines that are actually drawn (and the positions of labels). Without the text plot you get the same between the parent contour and the child lines plot. With text they might be a bit different, because the individual limits get composed.

I think this is one of those cases that could use some stronger definitions. What do we mean with data_limits? Is it related to the raw input data of a plot (old) or the data that gets visualized (new)? Given the context of plotting I'd say the latter.

@t-bltg t-bltg changed the title Contour limits changed from 0.19.9 to 0.19.10 Contour limits changed from 0.19.9 to 0.19.10 Oct 25, 2023
@ffreyer
Copy link
Collaborator

ffreyer commented May 24, 2024

This has been reverted in 0.21 for better or worse...

@ffreyer
Copy link
Collaborator

ffreyer commented Aug 26, 2024

Closing this as fixed

@ffreyer ffreyer closed this as completed Aug 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants