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:
- close window and plot next signal in a new window. (how to do it?)
- clear the current window contents and update it with the new plot. (how to do it?)
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
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):
plotobj = gui()
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:
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:
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:
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.
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.
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.
I just updated InspectDR so that the plot object (
GtkPlot) supports the
close() function, so you can write code that is a bit cleaner:
plotobj = gui()
But this will not work until you get a more recent version of gtk running (one that supports
So until then, you should stick with your own workaround.
I added a function you can use to clear the data in an InspectDR plot:
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.
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.