Skip to content

Commit

Permalink
Add lplot! for energy histogram of A/E cut
Browse files Browse the repository at this point in the history
  • Loading branch information
fhagemann committed Feb 24, 2025
1 parent c2294aa commit fdf308b
Showing 1 changed file with 50 additions and 15 deletions.
65 changes: 50 additions & 15 deletions ext/recipes/lplot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,8 @@ function LegendMakie.lplot!(
ax2.yticklabelspace = yspace
end

all = Makie.Axis(g[:,:])
Makie.hidedecorations!(all)
Makie.hidespines!(all)
Makie.current_axis!(all)

# add watermarks
Makie.current_axis!(ax)
watermark && LegendMakie.add_watermarks!(; kwargs...)

fig
Expand Down Expand Up @@ -122,12 +119,8 @@ function LegendMakie.lplot!(
ax2.yticklabelspace = yspace
end

all = Makie.Axis(g[:,:])
Makie.hidedecorations!(all)
Makie.hidespines!(all)
Makie.current_axis!(all)

# add watermarks
Makie.current_axis!(ax)
watermark && LegendMakie.add_watermarks!(; kwargs...)

fig
Expand Down Expand Up @@ -180,18 +173,60 @@ function LegendMakie.lplot!(
ax2.yticklabelspace = yspace
end

all = Makie.Axis(g[:,:])
Makie.hidedecorations!(all)
Makie.hidespines!(all)
Makie.current_axis!(all)

# add watermarks
Makie.current_axis!(ax)
watermark && LegendMakie.add_watermarks!(; kwargs...)

fig
end


function LegendMakie.lplot!(

Check warning on line 184 in ext/recipes/lplot.jl

View check run for this annotation

Codecov / codecov/patch

ext/recipes/lplot.jl#L184

Added line #L184 was not covered by tests
report::NamedTuple{(:h_before, :h_after_low, :h_after_ds, :dep_h_before, :dep_h_after_low, :dep_h_after_ds, :sf, :n0, :lowcut, :highcut, :e_unit, :bin_width)};
title::AbstractString = "", watermark::Bool = true, final::Bool = true, kwargs...
)

fig = Makie.current_figure()

Check warning on line 189 in ext/recipes/lplot.jl

View check run for this annotation

Codecov / codecov/patch

ext/recipes/lplot.jl#L189

Added line #L189 was not covered by tests

# create main histogram plot
ax = Makie.Axis(fig[1,1],

Check warning on line 192 in ext/recipes/lplot.jl

View check run for this annotation

Codecov / codecov/patch

ext/recipes/lplot.jl#L192

Added line #L192 was not covered by tests
title = title, limits = ((0,2700), (1,maximum(report.h_before.weights) * 1.2)), yscale = Makie.log10,
xlabel = "Energy (keV)", ylabel = "Counts / $(round(step(first(report.h_before.edges)), digits = 2)) keV",
)
Makie.stephist!(ax, StatsBase.midpoints(first(report.h_before.edges)), weights = report.h_before.weights, bins = first(report.h_before.edges), color = (LegendMakie.AchatBlue, 0.5), label = "Before A/E")
Makie.stephist!(ax, StatsBase.midpoints(first(report.h_after_low.edges)), weights = report.h_after_low.weights, bins = first(report.h_after_low.edges), color = (LegendMakie.BEGeOrange, 1), label = "After low A/E")
Makie.stephist!(ax, StatsBase.midpoints(first(report.h_after_ds.edges)), weights = report.h_after_ds.weights, bins = first(report.h_after_ds.edges), color = (LegendMakie.CoaxGreen, 0.5), label = "After DS A/E")
Makie.axislegend(ax, position = (0.96,1))

Check warning on line 199 in ext/recipes/lplot.jl

View check run for this annotation

Codecov / codecov/patch

ext/recipes/lplot.jl#L196-L199

Added lines #L196 - L199 were not covered by tests

# add inset
ax_inset = Makie.Axis(fig[1,1],

Check warning on line 202 in ext/recipes/lplot.jl

View check run for this annotation

Codecov / codecov/patch

ext/recipes/lplot.jl#L202

Added line #L202 was not covered by tests
width = Makie.Relative(0.4),
height = Makie.Relative(0.2),
halign = 0.55,
valign = 0.95,
yscale = Makie.log10,
xlabel = "Energy (keV)",
ylabel = "Counts",
xticks = 1585:10:1645,
xlabelsize = 12pt,
ylabelsize = 12pt,
xticklabelsize = 10pt,
yticklabelsize = 10pt,
yticks = (exp10.(0:10), "1" .* join.(fill.("0", 0:10))),
limits = (extrema(first(report.dep_h_before.edges)), (0.9, max(100, maximum(report.dep_h_before.weights)) * 1.2))
)
Makie.stephist!(ax_inset, StatsBase.midpoints(first(report.dep_h_before.edges)), weights = replace(report.dep_h_before.weights, 0 => 1e-10), bins = first(report.dep_h_before.edges), color = (LegendMakie.AchatBlue, 0.5), label = "Before A/E")
Makie.stephist!(ax_inset, StatsBase.midpoints(first(report.dep_h_after_low.edges)), weights = replace(report.dep_h_after_low.weights, 0 => 1e-10), bins = first(report.dep_h_after_low.edges), color = (LegendMakie.BEGeOrange, 1), label = "After low A/E")
Makie.stephist!(ax_inset, StatsBase.midpoints(first(report.dep_h_after_ds.edges)), weights = replace(report.dep_h_after_ds.weights, 0 => 1e-10), bins = first(report.dep_h_after_ds.edges), color = (LegendMakie.CoaxGreen, 0.5), label = "After DS A/E")

Check warning on line 220 in ext/recipes/lplot.jl

View check run for this annotation

Codecov / codecov/patch

ext/recipes/lplot.jl#L218-L220

Added lines #L218 - L220 were not covered by tests

# add watermarks
Makie.current_axis!(ax)
watermark && LegendMakie.add_watermarks!(; final, kwargs...)

Check warning on line 224 in ext/recipes/lplot.jl

View check run for this annotation

Codecov / codecov/patch

ext/recipes/lplot.jl#L223-L224

Added lines #L223 - L224 were not covered by tests

fig

Check warning on line 226 in ext/recipes/lplot.jl

View check run for this annotation

Codecov / codecov/patch

ext/recipes/lplot.jl#L226

Added line #L226 was not covered by tests
end


function LegendMakie.lplot!(
report::NamedTuple{(:par, :f_fit, :x, :y, :gof, :e_unit, :label_y, :label_fit)},
com_report::NamedTuple{(:values, :label_y, :label_fit, :energy)};
Expand Down

0 comments on commit fdf308b

Please sign in to comment.