How to make plot! work with new plot method

Hello,

I added new methods for plot and histogram to work with a custom type. Both methods work in isolation, but I cannot combine them by calling plot and then histogram! for example. How can I allow plot! and histogram! to work?

Below is a simplification of my problem. Most cases involve subplots, so I added those.


struct MyType end 

import Plots: plot, histogram

function plot(::MyType)
    plot(rand(2), title="MyType", layout=(2,1))
end

function histogram(::MyType)
    histogram(rand(200), title="MyType", layout=(2,1))
end

Works:

plot(MyType())

Works:

histogram(MyType())

Fails:

plot(MyType())
histogram!(MyType())

After digging through code in Plots.jl, I found Plots.current. I’m not sure if this is recommended, but it appears to work:

import Plots: histogram! 

histogram!(T::MyType) = histogram!(Plots.current(), T)

function histogram!(cur_plot, ::MyType)
    histogram!(cur_plot, rand(200), title="MyType", layout=(2,1))
end

Is there a better approach?