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

fix error bar range in recipes #3179

Merged
merged 5 commits into from Aug 25, 2023

Conversation

palday
Copy link
Contributor

@palday palday commented Aug 24, 2023

Description

Fixes #3176

Moves to data space instead of pixel space.

Type of change

Delete options that do not apply:

  • Bug fix (non-breaking change which fixes an issue)

Checklist

  • Added an entry in NEWS.md (for new features and breaking changes)
  • Added or changed relevant sections in the documentation
  • Added unit tests for new algorithms, conversion methods, etc.
  • Added reference image tests for new plotting functions, recipes, visual options, etc.

@ffreyer
Copy link
Collaborator

ffreyer commented Aug 24, 2023

Rather than reverting this change we should probably have a custom data_limits method like bracket for now

data_limits(pl::Bracket) = mapreduce(union, pl[1][]) do points
Rect3f([points...])
end

and figure out a clean way to ignore non data space limits in Axis later, maybe as part of #3040.

@palday
Copy link
Contributor Author

palday commented Aug 24, 2023

@ffreyer there's already a custom data_limits

# ignore whiskers when determining data limits
function data_limits(bars::Union{Errorbars, Rangebars})
data_limits(bars.plots[1])
end

but I don't know enough to know how to update it to fix this problem

@ffreyer
Copy link
Collaborator

ffreyer commented Aug 24, 2023

Huh, why doesn't that work then? Is that not getting called when updating limits?

@ffreyer
Copy link
Collaborator

ffreyer commented Aug 24, 2023

Oh ok, the problem comes from errorbars being wrapped in another plot recipe. In this case Axis calls

function data_limits(plot::AbstractPlot)
limits_from_transformed_points(iterate_transformed(plot))
end

which goes into
function iterate_transformed(plot)
points = point_iterator(plot)
t = transformation(plot)
model = model_transform(t)
# TODO: without this, axes with log scales error. Why?
trans_func = identity # transform_func(t)
# trans_func = identity
iterate_transformed(points, model, to_value(get(plot, :space, :data)), trans_func)
end

and further into
point_iterator(plot::Combined) = point_iterator(plot.plots)

skipping the custom data_limits.

So if we swap out the data_limits function for

function point_iterator(bars::Union{Errorbars, Rangebars})
    point_iterator(bars.plots[1])
end

we should be good. If that works could you skim through the other plot recipes in basic_plots and stats and replace the other overwrites as well?

@palday
Copy link
Contributor Author

palday commented Aug 24, 2023

The only other use in basic_recipes was your example from bracket.jl and a keywarg to axis3d!:

function axis3d!(scene::Scene, lims = data_limits(scene, p -> isaxis(p) || not_in_data_space(p)); kw...)
axis3d!(scene, Attributes(), lims; ticks = (ranges = automatic, labels = automatic), kw...)
end

In stats, we have:

function data_limits(hb::Hexbin)
bb = Rect3f(hb.plots[1][1][])
fn(num::Real) = Float32(num)
fn(tup::Union{Tuple,Vec2}) = Vec2f(tup...)
ms = 2 .* fn(hb.plots[1].markersize[])
nw = widths(bb) .+ (ms..., 0.0f0)
no = bb.origin .- ((ms ./ 2.0f0)..., 0.0f0)
return Rect3f(no, nw)
end

Let me know if I should change either or both of those to be point_iterator instead of data_limits

@ffreyer
Copy link
Collaborator

ffreyer commented Aug 24, 2023

axis3d! is fine, the other two would be good to change. For hexbin I think you can just call decompose(Point2f, Rect3f(no, nw)) to keep it simple

@jkrumbiegel
Copy link
Collaborator

jkrumbiegel commented Aug 25, 2023

I wonder if this makes sense

function iterate_transformed(plot) 
     points = point_iterator(plot) 
     t = transformation(plot) 
     model = model_transform(t) 
     # TODO: without this, axes with log scales error.  Why? 
     trans_func = identity # transform_func(t) 
     # trans_func = identity 
     iterate_transformed(points, model, to_value(get(plot, :space, :data)), trans_func) 
 end 

Because the transformation / model of a parent plot doesn't affect its children directly, does it? But we seem to want to transform by it (although not really as trans_func is set to identity for some reason)

Maybe this one

function data_limits(plot::AbstractPlot) 
     limits_from_transformed_points(iterate_transformed(plot)) 
 end 

needs to be rewritten so that it just combines the limits of its children, and doesn't iterate directly over them.

@ffreyer
Copy link
Collaborator

ffreyer commented Aug 25, 2023

Yea, but I think it's better to have this be a quick fix and consider changes to data_limits more wholistically with #2881 / #3040.

@jkrumbiegel
Copy link
Collaborator

I'm ok with that

@SimonDanisch SimonDanisch mentioned this pull request Aug 25, 2023
@ffreyer ffreyer merged commit b9f25b9 into MakieOrg:master Aug 25, 2023
13 checks passed
@SimonDanisch
Copy link
Member

Thank you!

@ffreyer ffreyer mentioned this pull request Aug 28, 2023
@ffreyer ffreyer mentioned this pull request Sep 12, 2023
7 tasks
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 this pull request may close these issues.

Auto limits broken with recipes on 0.19.7 and 0.19.8
4 participants