I have a histogram type that I’d like to customize its plotting for a few type of plots: Scatter, BarPlot, Hist, StepHist etc.
For some of them, this is very straight forward:
julia> using CairoMakie
julia> struct MyHist
bincounts
binedges
end
julia> h = MyHist([1, 10, 100], 0:3)
julia> Makie.convert_arguments(P::Type{<:Stairs}, h::MyHist) = convert_arguments(P, h.binedges, [0; h.bincounts])
julia> stairs(h)
However, for plot type such as StepHist
, I failed to properly “override” the plot, what I tried is to define:
function Makie.plot!(input::StepHist{<:Tuple{<:MyHist}})
h = input[1][]
Makie.stairs!(input, h)
input
end
this works in the naive case, which would produce exactly the same plot as above:
julia> h = MyHist([1, 10, 100], 0:3)
julia> stephist(h)
However, it fails when we use it together with other stuff:
stephist(h; color=:red)
So initially I tried to fix this by changing the definition of plot!()
to:
function Makie.plot!(input::StepHist{<:Tuple{<:MyHist}})
h = input[1][]
C = input[:color][]
Makie.stairs!(input, h; color=C)
input
end
now this works:
stephist(h; color=:red)
but there are edge cases like:
julia> begin
stephist(h);
h2 = MyHist([5, 20, 120], 0:3)
stairs!(h2)
current_figure()
end
Notice one is stephist
the other is stairs!
, that produce:
Notice, if we delete the color = C)
part from the plot!()
function above, the latest code plots the colors as expected: