# How to make plot! work with new plot method

**URL:** <https://discourse.julialang.org/t/how-to-make-plot-work-with-new-plot-method/101621>\
**Category:** General Usage\
**Tags:** question, plotting, recipe\
**Created:** [July 14, 2023, 12:55pm UTC](https://discourse.julialang.org/t/how-to-make-plot-work-with-new-plot-method/101621 "2023-07-14T12:55:28Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Christopher\_Fisher](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/christopher_fisher/32/26132_2.png) [@Christopher\_Fisher](https://discourse.julialang.org/u/Christopher_Fisher)\
**Post date:** [July 14, 2023, 12:55pm UTC](https://discourse.julialang.org/t/how-to-make-plot-work-with-new-plot-method/101621/1 "2023-07-14T12:55:29Z")

</div>

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.

```julia

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:

```julia
plot(MyType())
histogram!(MyType())

```

---

<div class="post-metadata">

**Author:** ![Christopher\_Fisher](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/christopher_fisher/32/26132_2.png) [@Christopher\_Fisher](https://discourse.julialang.org/u/Christopher_Fisher)\
**Post date:** [July 14, 2023, 1:09pm UTC](https://discourse.julialang.org/t/how-to-make-plot-work-with-new-plot-method/101621/2 "2023-07-14T13:09:22Z")

</div>

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

```julia
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?
