Skip to content

Commit

Permalink
Merge pull request #4 from legend-exp/fallback
Browse files Browse the repository at this point in the history
Add fallback method for `lplot!`
  • Loading branch information
fhagemann authored Feb 20, 2025
2 parents c2294aa + adb6f97 commit 446973e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
25 changes: 25 additions & 0 deletions ext/recipes/lplot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -205,5 +205,30 @@ function LegendMakie.lplot!(
Makie.lines!(ax, com_report.energy, com_report.values, linewidth = 4, color = :red, linestyle = :dash, label = LaTeXStrings.latexstring("\\fontfamily{Roboto}" * com_report.label_fit))
Makie.axislegend(ax, position = legend_position)

fig
end


function LegendMakie.lplot!(args...; watermark::Bool = false, kwargs...)

fig = Makie.current_figure()

#create plot
ax = if !isnothing(Makie.current_axis())
Makie.current_axis()
else
Makie.Axis(fig[1,1],
titlesize = 18,
titlegap = 1,
titlealign = :right
)
end

# use built-in method as fallback if existent, tweak appearance
Makie.plot!(args...; kwargs...)

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

fig
end
1 change: 1 addition & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
LegendSpecFits = "18221496-77af-46cf-bab8-820da09f7f97"
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
RadiationDetectorSignals = "bf2c0563-65cf-5db2-a620-ceb7de82658c"
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"

Expand Down
3 changes: 2 additions & 1 deletion test/test_lplot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ using Makie

import LegendSpecFits
import Distributions
import StatsBase
import Unitful: @u_str

using Test
Expand All @@ -16,7 +17,7 @@ using Test

# test default watermark
ax = Axis(fig[1,1])
hist!(ax, randn(10000))
@test_nowarn lplot!(StatsBase.fit(StatsBase.Histogram, randn(10000)))
@test_nowarn LegendMakie.add_watermarks!()

# test alternative watermark
Expand Down

0 comments on commit 446973e

Please sign in to comment.