How to change window size of InspectDR

I am not able to change the size of the plot window. Example code:

using Plots; inspectdr()

x=0:0.05:100
y1=sin.(x)

p1 = plot(x,y1, size=(1200,700), legend=false)
display(p1);

The size is always small, about 640x480. How can I increase the initial size of the plot window?

Hi @ufechner7,

When I implemented the inspectdr() backend to Plots.jl, I was interpreting things a bit different

  • I assumed size=(1200,700) would affect only sizes of exported images (svg/png/…).

Also:
As a general philosophy, the InspectDR package does not control the window size programmatically when you specify “plot size”. Instead, it assumes:

  • users will want to be in control window size.
  • InspectDR just has to make things fit according to the end-user’s wishes.
  • and, just to repeat: “plot size” is assumed to affect size of exported images.

GTK resize!() interface

That said: InspectDR is based on GTK, and so you can resize the window using GTK:

using Plots; inspectdr()

x=0:0.05:100
y1=sin.(x)

p1 = plot(x,y1, legend=false)
pIDR=display(p1); #Display with InspectDR and keep plot object
resize!(pIDR.wnd, 1200, 700) #Resize GTK window directly

I hope this doesn’t feel to inelegant as a solution.

2 Likes

@MA_Laforge, could you please comment on the basic differences between the Plots’ object p1 and the GtkPlot object display(p1)?

Running p1 or display(p1) produce the same result (open the plot window) but they are not the same thing…

Thank you.

This works fine for me, thank you!

Bonus question: Is there a way to turn off/ toggle the x-axis control slider from the script?

Two options:

#Individually disable each x-axis control (execute after plotting):
InspectDR.xaxisctrl_visible(pIDR.subplots[1], false)

#Disable x-axis control by default from now on (execute before plotting):
InspectDR.defaults.xaxiscontrol_visible = false
2 Likes

Actually, they are the same thing. If you execute p1 in the REPL or in a Jupyter notebook, it basically calls display(p1).

But something is technically wrong with my implementation

Pseudocode for correct implementation of display(p1):

function Base.display(d::Display, plot::Plots.Plot)
    nativeplot = build_native(plot)
    #NOTE: we ignore `d` here because we don't care that d=REPL
    #      ...We just want to pop-up a GUI, and display it.
    display(nativeplot) #display here should really return `nothing`
end

Here something is missing

  • Plots.jl does not provide a build_native() function for users to call (as far as I know).
  • So there isn’t really a way I know of for users to get a plot object native to the backend.
  • (If so, I should probably implement that interface instead - it would be cleaner).
  • So I instead hacked the display() call (see below).

Here is my hack

Pseudocode for correct implementation of display(p1):

function Base.display(d::Display, plot::Plots.Plot)
    nativeplot = build_native(plot)
    display(nativeplot) #display here should really return `nothing`
    return nativeplot #You probably shouldn't return non-`nothing` values
end

Weird consequence of this hack

  • If you call display(p1) from the repl, the call to display() will show the plot.
  • If that display() function returns an object (like I’m doing here)… then the REPL will call display() on THAT object.

So I technically SHOULDN’T return my native plot object from the call to display().

But luckily, the object I return doesn’t display itself again (It just prints out something like GtkPlot("", 1 subplots)).

Comment

This is just pseudocode of course. In reality, the function calls I use have different names/arguments.

1 Like

Plots.jl has backend_object which assumes you store the backend object in Plot.o.

1 Like

True. I wasn’t thinking about that when I originally wrote the code.

@ufechner7: That means the code you should actually use is:

using Plots; inspectdr()

x=0:0.05:100
y1=sin.(x)

p1 = plot(x,y1, legend=false)
display(p1); #Display (building InspectDR plot object & writing to `p1.o`)
pIDR = p1.o.gui
resize!(pIDR.wnd, 1200, 700) #Resize GTK window directly

I should fix the Plots/InspectDR display() function so as to return nothing – thus avoiding this double-display issue.

Generate/without displaying?

@BeastyBlacksmith: Just out of curiosity: is there also a way to trigger Plots.jl to build the native plot without displaying/saving the plot?

(i.e.: Without calling display(plt) or saving (ex: png(plt, filename)?)

Just to be clear the API is backend_object and thus it should be

using Plots; inspectdr()

x=0:0.05:100
y1=sin.(x)

p1 = plot(x,y1, legend=false)
display(p1); #Display (building InspectDR plot object & writing to `p1.o`)
pIDR = backend_object(p1).gui
resize!(pIDR.wnd, 1200, 700) #Resize GTK window directly

There is no official API for that, but you could call Plots._update_plot_object for that.

1 Like