How to close InspectDR plot window or update it?

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?)
using Plots
using InspectDR
inspectdr()
plot(1:100)
gui()

Hi,

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

@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).

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):

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.

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:

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:

#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:

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.

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. I could only go around it by manually downloading the old gtk bundle 3.6.4.), so now I got this error:

InspectDR.window_close(plotobj.wnd)
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:

InspectDR._Gtk.destroy(plotobj.wnd)

This closes the figure.

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

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.

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:

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:

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.

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.