# Display plot in GTK without saving to PNG

**URL:** <https://discourse.julialang.org/t/display-plot-in-gtk-without-saving-to-png/113330>\
**Category:** New to Julia\
**Tags:** question, package, plotting\
**Created:** [April 22, 2024, 11:21am UTC](https://discourse.julialang.org/t/display-plot-in-gtk-without-saving-to-png/113330 "2024-04-22T11:21:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![C1wan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/c1wan/32/208691_2.png) [@C1wan](https://discourse.julialang.org/u/C1wan)\
**Post date:** [April 22, 2024, 11:21am UTC](https://discourse.julialang.org/t/display-plot-in-gtk-without-saving-to-png/113330/1 "2024-04-22T11:21:19Z")

</div>

Hello,

I have an application where I display a plot in a GTK window, but for that I save it in a png with  
savefig and CairoImageSurface. Now I want do display the plot without saving i to a PNG file. Normally this should work by giving CairoImageSurface an array instead of a RGB24 object. But it didnt work

```julia
using Cairo, Plots, Statsplots, Statsbase

function make_hist(arr)
#creates histogram from array
...
return plotFig
end

function display_hist(plotFig, arr)
#savefig("plot.png")
...
# instead of saving it to a png display it directly with Cairo
# this doesnt work even when trying to reshape the array
hist = CairoImageSurface(arr, (2,2))

end

plotFig = makehist(arr)
display_hist(plotFig)

```

---

<div class="post-metadata">

**Author:** ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Post date:** [April 22, 2024, 1:07pm UTC](https://discourse.julialang.org/t/display-plot-in-gtk-without-saving-to-png/113330/2 "2024-04-22T13:07:13Z")

</div>

Can you elaborate on why it did not work? Also how are you running the code?

One reason I ask is that I do not see anything that will prevent Julia from exiting immediately after it tries to display the plot.
