# How to close InspectDR plot window or update it?

**URL:** <https://discourse.julialang.org/t/how-to-close-inspectdr-plot-window-or-update-it/25787>\
**Category:** Visualization\
**Tags:** inspectdr\
**Created:** [June 28, 2019, 7:05am UTC](https://discourse.julialang.org/t/how-to-close-inspectdr-plot-window-or-update-it/25787 "2019-06-28T07:05:25Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Iulian.Cioarca](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/iulian.cioarca/32/30166_2.png) [@Iulian.Cioarca](https://discourse.julialang.org/u/Iulian.Cioarca)\
**Post date:** [June 28, 2019, 7:05am UTC](https://discourse.julialang.org/t/how-to-close-inspectdr-plot-window-or-update-it/25787/1 "2019-06-28T07:05:25Z")

</div>

Hi,

Sorry for the noob question, but I searched through some documentation and examples of InspectDR and could not figure out how to close a plot window. Can someone point me in the right direction, please? I’m sure I missed something. Thank you!

Some info about my task: I am plotting hundreds of signals in order to label them(I have a small GUI that blocks plotting the next signal until I tell it to) so the screen will fill up with windows. I thought of two solutions for this:

1. close window and plot next signal in a new window. (how to do it?)
2. clear the current window contents and update it with the new plot. (how to do it?)

```julia
using Plots
using InspectDR
inspectdr()
plot(1:100)
gui()

```

---

<div class="post-metadata">

**Author:** ![MA\_Laforge](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ma_laforge/32/385_2.png) [@MA\_Laforge](https://discourse.julialang.org/u/MA_Laforge)\
**Post date:** [June 30, 2019, 7:39pm UTC](https://discourse.julialang.org/t/how-to-close-inspectdr-plot-window-or-update-it/25787/2 "2019-06-30T19:39:03Z")

</div>

Hi,

Before I answer: If you have a specific question about `InspectDR`, feel free to “ping” me using the “@” symbol. For example:

```julia
@MA_Laforge: I am having trouble with ... 

```

I just don’t poll the forums everyday, so there’s a better chance I will see your question this way (“Discourse” is supposed to send me an email when you do this).

---

<div class="post-metadata">

**Author:** ![MA\_Laforge](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ma_laforge/32/385_2.png) [@MA\_Laforge](https://discourse.julialang.org/u/MA_Laforge)\
**Post date:** [June 30, 2019, 7:46pm UTC](https://discourse.julialang.org/t/how-to-close-inspectdr-plot-window-or-update-it/25787/3 "2019-06-30T19:46:05Z")

</div>

### How to close the last `InspectDR` window

I did not plan for this for some reason - but it sounds like a reasonable feature request. I will open an issue to add a proper function.

For the time being, you can still close InspectDR’s Gtk window through some “private functions” (not really intended to be public/supported):

```julia-auto
using Plots
using InspectDR
inspectdr()
plot(1:100)
plotobj = gui()

InspectDR.window_close(plotobj.wnd)

```

Note that the `gui()` function returns a reference to an `InspectDR` plot object - and that the `window_close()` function calls the `Gtk` function to close windows.

---

<div class="post-metadata">

**Author:** ![MA\_Laforge](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ma_laforge/32/385_2.png) [@MA\_Laforge](https://discourse.julialang.org/u/MA_Laforge)\
**Post date:** [June 30, 2019, 8:02pm UTC](https://discourse.julialang.org/t/how-to-close-inspectdr-plot-window-or-update-it/25787/4 "2019-06-30T20:02:51Z")

</div>

### Overwriting data on a current plot

@mkborregaard: You are usually good with these kind of questions (I think most people shy away from answering because the question _ **sounds** _ InspectDR-specific).

I know you can _ **add** _ a signal to an existing plot using the following:

```julia-auto
using Plots
using InspectDR
inspectdr()
p = plot(rand(100)) #Add first signal

p=plot!(p, rand(100)) #Add some other signal
p=plot!(p, rand(100)) #...And another

plotobj = gui()

```

But I don’t see a mechanism to _ **overwrite** _ the data in the current plot. For example, I know this _ **does not work** _:

```julia-auto
#Let's say now that I want to OVERWRITE contents of plot "p":
p=plot(p, rand(100)) #will not work (no such function available)

```

Otherwise, I would have expected there to be a function that could clear all data from the plot, for example:

```julia-auto
clear_data(p) #Is there something like this in plots?

```

I would normally suggest accessing the internal structures of the `Plot` object, but I don’t actually think this is a good idea given how `Plots.jl` is designed.

---

<div class="post-metadata">

**Author:** ![Iulian.Cioarca](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/iulian.cioarca/32/30166_2.png) [@Iulian.Cioarca](https://discourse.julialang.org/u/Iulian.Cioarca)\
**Post date:** [July 1, 2019, 12:32pm UTC](https://discourse.julialang.org/t/how-to-close-inspectdr-plot-window-or-update-it/25787/5 "2019-07-01T12:32:52Z")

</div>

Thank you very much for the suggestions!  
Unfortunately I discovered I have a very old gtk library(because of the ‘resurfacing issue of WinRPM’ : [https://github.com/JuliaGraphics/Cairo.jl/issues/284](https://github.com/JuliaGraphics/Cairo.jl/issues/284). I could only go around it by manually downloading the old gtk bundle 3.6.4.), so now I got this error:

```julia
InspectDR.window_close(plotobj.wnd)

```

```julia
ccall: could not find function gtk_window_close in library C:\Users\cioarca\.julia\packages\WinRPM\Y9QdZ\deps\usr\x86_64-w64-mingw32\sys-root\mingw\bin\libgtk-3-0.DLL

```

Meanwhile I poked around InspectDR and found:

```julia
InspectDR._Gtk.destroy(plotobj.wnd)

```

This closes the figure.

---

<div class="post-metadata">

**Author:** ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)\
**Post date:** [July 2, 2019, 7:40am UTC](https://discourse.julialang.org/t/how-to-close-inspectdr-plot-window-or-update-it/25787/6 "2019-07-02T07:40:57Z")

</div>

I don’t think there’s any inbuilt mechanism for overwriting data, other than accessing the internals of the object directly, unfortunately.

---

<div class="post-metadata">

**Author:** ![MA\_Laforge](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ma_laforge/32/385_2.png) [@MA\_Laforge](https://discourse.julialang.org/u/MA_Laforge)\
**Post date:** [July 2, 2019, 2:06pm UTC](https://discourse.julialang.org/t/how-to-close-inspectdr-plot-window-or-update-it/25787/7 "2019-07-02T14:06:05Z")

</div>

Thanks Michael. I thought that was probably the case, but I have been unaware of more obscure features of Plots.jl in the past.

@Iulian.Cioarca:

I will probably add something like a `clear_data()` function to InspectDR in the near future.

The idea of re-using the same plot multiple times was not originally one of my use case senarios, but I don’t find it that unreasonable.

Also:  
Thanks for telling me about the fact that `gtk_window_close` is unsupported in older versions of gtk. I do not _ **plan** _ to support these older versions - but if we keep getting issues with the newer versions, I might end up having to add some form of backwards compatibility.

---

<div class="post-metadata">

**Author:** ![MA\_Laforge](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ma_laforge/32/385_2.png) [@MA\_Laforge](https://discourse.julialang.org/u/MA_Laforge)\
**Post date:** [July 9, 2019, 1:36am UTC](https://discourse.julialang.org/t/how-to-close-inspectdr-plot-window-or-update-it/25787/8 "2019-07-09T01:36:19Z")

</div>

Hi @Iulian.Cioarca:

I just updated InspectDR so that the plot object (`GtkPlot`) supports the `close()` function, so you can write code that is a bit cleaner:

```julia-auto
using Plots
using InspectDR
inspectdr()
plot(1:100)
plotobj = gui()

close(plotobj)

```

But this will not work until you get a more recent version of gtk running (one that supports `gtk_window_close`).

So until then, you should stick with your own workaround.

### Also:

I added a function you can use to clear the data in an InspectDR plot:

```julia-auto
clear_data(plotobj)

```

Sadly, this will not work when using Plots.jl - because Plots.jl ignores these values and always rebuilds a new plot window with the data it keeps in its own data structures.

---

<div class="post-metadata">

**Author:** ![Iulian.Cioarca](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/iulian.cioarca/32/30166_2.png) [@Iulian.Cioarca](https://discourse.julialang.org/u/Iulian.Cioarca)\
**Post date:** [July 9, 2019, 3:55pm UTC](https://discourse.julialang.org/t/how-to-close-inspectdr-plot-window-or-update-it/25787/9 "2019-07-09T15:55:56Z")

</div>

Hi, @MA_Laforge:

Many thanks for your help!  
I will give it a try under Ubuntu, but meanwhile I will use InspectDR.\_Gtk.destroy(plotobj.wnd) until the gtk issue will be solved on Windows.
