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

[FR] Plot recipe: ribbon plots option beside error bars #109

Open
kapple19 opened this issue Aug 10, 2021 · 11 comments
Open

[FR] Plot recipe: ribbon plots option beside error bars #109

kapple19 opened this issue Aug 10, 2021 · 11 comments

Comments

@kapple19
Copy link

kapple19 commented Aug 10, 2021

I'm happy to submit a pull request on this, I just want to confirm that the package devs are happy with this suggestion: add a ribbon option for the plot output. Motivation: Plots.jl and Measurements.jl don't have a simple "switch" to flick to use the readily-available info in a Measurement instance of the ± information.

I'm not sure if I would (1) add a new recipe to plot-recipes.jl or (2) alter an existing recipe.

The recipe I could alter would be something like

@recipe function plot(x::AbstractVector{<:Real}, y::AbstractVector{<:Measurement}, err::Symbol = :bar)
	if err == :ribbon
		ribbon := uncertainty.(y)
	elseif err == :bar
		yerror := uncertainty.(y)
	else
		error("Unrecognized error bar display option.")
	end
	x, value.(y)
end

Please advise, this would be my first ever pull request, and I'm still learning about Plots.jl recipes. Thanks for the great package!

@giordano
Copy link
Member

Hi, thanks for the interest! I agree that having the ability to choose between a ribbon and error bars would be cool, but I have two concerns:

  • does the ribbon make sense if you plot vectors? Or is it better to use it only for something smooth, like a function (plot(f, x))? Probably the distinction vectors vs function as input is moot, so maybe this concern is not too relevant, not sure
  • you suggest to add a keyword argument (I don't like err very much though, a bit cryptic and confusing), but how does that work in practice? Does it compose with other keyword arguments defined by other recipes? I never explored this possibility, I really don't know how this works

If you can provide answers to these questions, I'd very much appreciate a pull request

@kapple19
Copy link
Author

does the ribbon make sense if you plot vectors? Or is it better to use it only for something smooth, like a function (plot(f, x))? Probably the distinction vectors vs function as input is moot, so maybe this concern is not too relevant, not sure

I agree, it's better for a function.

I don't like err very much

Yeah me too, I can't think of a name.

Does it compose with other keyword arguments defined by other recipes?

Yes, it does! I did test this one out. It adds err (or whatever we might choose) to the optional arguments. I might test it a bit more to see how it behaves in different order, if it's better as a keyword argument, etc.

I'd very much appreciate a pull request

Okay cool. As I was writing this issue, I realised that I would need to do more experimenting and digging into the bigger picture of Measurements.jl and RecipesBase.jl to understand the best way to do this. I'll let you know once I've rigorously and thoroughly thought out some potential solution(s). Thanks @giordano!

@dfabianus
Copy link

Hello! :) Is there something new to this? I would use this quite often for model simulations where ribbons are way more effective than error bars.

My workaround right now is something like this:

y1 = Measurements.value.(y_meas)
y1u = Measurements.uncertainty.(y_meas)
# creating the ribbon
p = plot(t, y1.-y1u, fillranges = y1.+y1u, fillalpha = 0.25, linewidth=0, label = "" , fillcolor = 1)
# plotting the mean value on top
p = plot!(t, y1, label = "model", color=1)

@giordano
Copy link
Member

Is there something new to this?

I already explained I don't know how to do this myself, if someone has a clear view of how to best implement this, they're welcome to submit a pull request. I don't think that has happened yet.

@kapple19
Copy link
Author

Hello! :) Is there something new to this? I would use this quite often for model simulations where ribbons are way more effective than error bars.

My apologies, I never followed through on this. I'll action it next chance I get.

@kapple19
Copy link
Author

kapple19 commented Jan 26, 2024

I have some changes on a local branch in a local clone, but I don't have permission to push. @giordano how would you like me to submit a pull request?

@kapple19
Copy link
Author

kapple19 commented Jan 26, 2024

@dfabianus here's a preview =)

x = range(0, 2π, 301)
yval = cospi.(x)
yunc = (5 .+ 2sinpi.(5x))/10
y = measurement.(yval, yunc)
plot(x, y,
    uncertainty_plot = :ribbon,
    label = "model",
    fillalpha = 0.25,
    color = 1
)

dfabianus

The defaults are inherited from Plots.jl of course:

plot(x, y, uncertainty_plot = :ribbon)

dfabianus_newer

Edit: Noticed the double pi in my definitions haha.

@giordano
Copy link
Member

Yes, please, open a PR!

@kapple19
Copy link
Author

kapple19 commented Jan 27, 2024

@giordano how do I get permission to push to JuliaPhysics/Measurements.jl? I can't open a pull request because I don't have permission to publish and push my branch to this repository.

@dfabianus
Copy link

Looks good @kapple19 ! Did you make a fork? To open a pull request usually you have to fork the repository first.
Have a look here:
https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request-from-a-fork

kapple19 added a commit to kapple19/Measurements.jl that referenced this issue Jan 27, 2024
kapple19 added a commit to kapple19/Measurements.jl that referenced this issue Jan 27, 2024
@kapple19
Copy link
Author

kapple19 commented Jan 27, 2024

Ah, thanks heaps! I didn't know I had to fork it.

Edit: I should add some unit tests actually.

kapple19 added a commit to kapple19/Measurements.jl that referenced this issue Jan 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants