# Delete/redraw plot in Makie

**URL:** <https://discourse.julialang.org/t/delete-redraw-plot-in-makie/55659>\
**Category:** Visualization\
**Tags:** makie, makielayout\
**Created:** [February 20, 2021, 1:38am UTC](https://discourse.julialang.org/t/delete-redraw-plot-in-makie/55659 "2021-02-20T01:38:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![darsnack](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/darsnack/32/10144_2.png) [@darsnack](https://discourse.julialang.org/u/darsnack)\
**Post date:** [February 20, 2021, 1:38am UTC](https://discourse.julialang.org/t/delete-redraw-plot-in-makie/55659/1 "2021-02-20T01:38:02Z")

</div>

I have a neural network and I am plotting its decision boundary using a trick with `contourf!` (basically make a 2D grid of points then apply the neural network to classify each point; contour line will end up on the decision boundary since there are only two levels). Now I want to do this plot every so often so I can see the boundary update as I train the neural network.

One thing I have considered is to make a `Node` with my neural network inside, but it really just seems easier to delete the old contour plot and re-plot it. Is there a way to do this in Makie?

Here’s the relevant plotting code:

```julia
function decisionboundary!(axis, m; f = x -> x > 0 ? 1 : 0, npts = 200, fill = false, pltargs...)
    xmin = 0.9 * minimum(axis.limits[])[1]
    xmax = 0.9 * maximum(axis.limits[])[1]
    ymin = 0.9 * minimum(axis.limits[])[2]
    ymax = 0.9 * maximum(axis.limits[])[2]
    Δx = (xmax - xmin) / npts
    Δy = (ymax - ymin) / npts
    x = range(xmin, step = Δx, length = npts)
    y = range(ymin, step = Δy, length = npts)
    features = vcat(repeat(reshape(x, 1, :), inner = (1, npts)), repeat(reshape(y, 1, :), outer = (1, npts)))
    Y = _applymodel(m, f, features, npts) # my attempt to lift the neural network

    if all(Y .== first(Y))
        @warn "Not drawing decision boundary because there is only one resulting class"
        return nothing
    end

    return fill ? contourf!(axis, vec(x), vec(y), Y; linewidth = 2, levels = 1, pltargs...) :
                  contour!(axis, vec(x), vec(y), Y; linewidth = 2, levels = 1, pltargs...)
end

function _applymodel(m, f, features, npts)
    Y = m(features)
    if size(Y, 1) == 1
        Y = f.(Y)
    else
        Y = f.(eachcol(Y))
    end
    Y = permutedims(reshape(Y, npts, npts))

    return Y
end
_applymodel(m::Node, f, features, npts) = @lift(_applymodel($m, f, features, npts))

```

---

<div class="post-metadata">

**Author:** ![darsnack](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/darsnack/32/10144_2.png) [@darsnack](https://discourse.julialang.org/u/darsnack)\
**Post date:** [February 20, 2021, 1:56am UTC](https://discourse.julialang.org/t/delete-redraw-plot-in-makie/55659/2 "2021-02-20T01:56:25Z")

</div>

Wow this actually just worked! All I did was

```julia
modeltrace = Node(m) # m is my neural network
decisionboundary!(axis, m)

```

then call `modeltrace[] = m` each time I want an update.

Makie is so awesome! Thank you @sdanisch and @jules for such an amazing package.
