# How to change window size of InspectDR

**URL:** <https://discourse.julialang.org/t/how-to-change-window-size-of-inspectdr/82268>\
**Category:** General Usage\
**Tags:** package, plotting, inspectdr\
**Created:** [June 5, 2022, 11:12am UTC](https://discourse.julialang.org/t/how-to-change-window-size-of-inspectdr/82268 "2022-06-05T11:12:52Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [June 5, 2022, 11:12am UTC](https://discourse.julialang.org/t/how-to-change-window-size-of-inspectdr/82268/1 "2022-06-05T11:12:53Z")

</div>

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

```julia
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?

---

<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 5, 2022, 8:50pm UTC](https://discourse.julialang.org/t/how-to-change-window-size-of-inspectdr/82268/2 "2022-06-05T20:50:11Z")

</div>

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:

```julia-auto
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.

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [June 5, 2022, 9:39pm UTC](https://discourse.julialang.org/t/how-to-change-window-size-of-inspectdr/82268/3 "2022-06-05T21:39:55Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [June 5, 2022, 9:46pm UTC](https://discourse.julialang.org/t/how-to-change-window-size-of-inspectdr/82268/4 "2022-06-05T21:46:56Z")

</div>

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?

---

<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 6, 2022, 1:22am UTC](https://discourse.julialang.org/t/how-to-change-window-size-of-inspectdr/82268/5 "2022-06-06T01:22:32Z")

</div>

> [@ufechner7](#):
>
> Bonus question: Is there a way to turn off/ toggle the x-axis control slider from the script?

Two options:

```julia
#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

```

---

<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 6, 2022, 1:49am UTC](https://discourse.julialang.org/t/how-to-change-window-size-of-inspectdr/82268/6 "2022-06-06T01:49:47Z")

</div>

> [@rafael.guerra](#):
>
> Running `p1` or `display(p1)` produce the same result (open the plot window) but they are not the same thing…

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

```julia-auto
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)`:

```julia-auto
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.

---

<div class="post-metadata">

**Author:** ![BeastyBlacksmith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/beastyblacksmith/32/4741_2.png) [@BeastyBlacksmith](https://discourse.julialang.org/u/BeastyBlacksmith)\
**Post date:** [June 21, 2022, 5:30pm UTC](https://discourse.julialang.org/t/how-to-change-window-size-of-inspectdr/82268/7 "2022-06-21T17:30:00Z")

</div>

> [@MA\_Laforge](#):
>
> So there isn’t really a way I know of for users to get a plot object native to the backend.

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

---

<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 22, 2022, 1:30am UTC](https://discourse.julialang.org/t/how-to-change-window-size-of-inspectdr/82268/8 "2022-06-22T01:30:56Z")

</div>

> [@BeastyBlacksmith](#):
>
> Plots.jl has `backend_object` which assumes you store the backend object in `Plot.o`.

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

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

```julia-auto
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)`?)

---

<div class="post-metadata">

**Author:** ![BeastyBlacksmith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/beastyblacksmith/32/4741_2.png) [@BeastyBlacksmith](https://discourse.julialang.org/u/BeastyBlacksmith)\
**Post date:** [June 22, 2022, 7:31am UTC](https://discourse.julialang.org/t/how-to-change-window-size-of-inspectdr/82268/9 "2022-06-22T07:31:30Z")

</div>

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

```julia
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

```

> [@MA\_Laforge](#):
>
> Just out of curiosity: is there also a way to trigger Plots.jl to build the native plot without displaying/saving the plot?

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

---

<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 25, 2022, 4:48pm UTC](https://discourse.julialang.org/t/how-to-change-window-size-of-inspectdr/82268/10 "2022-06-25T16:48:48Z")

</div>

> [@BeastyBlacksmith](#):
>
> Just to be clear the API is `backend_object` and thus it should be

Ah. I see. I was unaware of that (didn’t catch on when you first mentioned it).  
Thanks.
