FHist.jl icon indicating copy to clipboard operation
FHist.jl copied to clipboard

[FR] Plotting recipe for a curve over a histogram

Open mmikhasenko opened this issue 1 year ago • 7 comments

I worked on plotting the recipe and dispatch in Plots.jl using Hist1D. The recipe might below on this package

  • model with data: WithData object, and
data = randn(1000);
h = Hist1D(data; binedges=range(-5,5, 100));
model_fun(x) = length(data) * exp(-x^2 / 2) / sqrt(2π);
plot(h, seriestype=:stepbins)
plot!(model_fun, WithData(h.binedges[1]), lw=2)

384034099-1651cb59-93e2-4956-a4b7-11a0a59d0650

  • curvedfitwithpulls for distribution with the pulls
data = log.(1 .+ (exp(1) - 1) .* rand(n))
best_model(x) = exp(x) / (exp(1)-1)
h = Hist1D(data; binedges=1.1:0.1:2.5))
curvedfitwithpulls(h0, best_model, xlab = "X-axis", ylab = "Y-axis")

384031006-cbcb7600-1991-4448-805b-372b1222ae6e

mmikhasenko avatar Nov 07 '24 15:11 mmikhasenko

for some reason images are gone

Moelf avatar Nov 07 '24 19:11 Moelf

The images are only visible to me for some funny reason (gone in incognito tab) Just updated

mmikhasenko avatar Nov 08 '24 09:11 mmikhasenko

my thoughts are the following:

  • I like this feature and I think they're useful and I'm sure they are generally useful
  • I don't like this feature is purely a plotting recipe, i.e. users can't extract the numbers from fitting.

It feels to me that, the "fitting with data" and "pull" should be their own objects, and they should have their own plotting recipe in a statistical package. And then, users can plot them as overlay on top of the histograms defined in this package.

Moelf avatar Nov 11 '24 02:11 Moelf

Thanks for the replies

The piece of information that the recipe creates is a pulls histogram. This histogram indeed can be useful as it is. There you are completely right - there should be a separate method creating just a histogram.

The other concern might come from unclear naming on my side:

  • the recipe does not fit anything, just scales by a number give to the WithData struct.

I think we can start with that, let me wipe out the curvedfitwithpulls making the PR small

mmikhasenko avatar Nov 11 '24 15:11 mmikhasenko

the recipe does not fit anything, just scales by a number give to the WithData struct.

oh I see, then in that case it feels even less useful to be a standalone thing? if it's just plotting a function evaluated at a set of x-points and scale it?

Moelf avatar Nov 11 '24 16:11 Moelf

yea + plotting style

mmikhasenko avatar Nov 11 '24 17:11 mmikhasenko

in this case I would suggest make that a standalone thing, such as https://github.com/aminnj/yahist

basically, FHist.jl feels like it should focus on histograms, not X + histograms.

I'm happy to add extensions or help maintaining them if you need X from histograms or X to histograms kind of functionality, but I feel like adding all X+histogram visualization is the wrong organization

Moelf avatar Nov 11 '24 17:11 Moelf