# Embedding plots in Gtk.jl

**URL:** <https://discourse.julialang.org/t/embedding-plots-in-gtk-jl/4085>\
**Category:** Visualization\
**Created:** [June 4, 2017, 7:27pm UTC](https://discourse.julialang.org/t/embedding-plots-in-gtk-jl/4085 "2017-06-04T19:27:44Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![piever](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/piever/32/1815_2.png) [@piever](https://discourse.julialang.org/u/piever)\
**Post date:** [June 4, 2017, 7:27pm UTC](https://discourse.julialang.org/t/embedding-plots-in-gtk-jl/4085/1 "2017-06-04T19:27:44Z")

</div>

I’m exploring the Gtk.jl package to create simple GUIs to visualize data and I wanted to ask if it is it possible to draw a plot created with some backend of Plots.jl (say GR for example) into a Gtk window. I seem to remember that this feature was available at some point, but I couldn’t find any relevant documentation.

---

<div class="post-metadata">

**Author:** ![ecx2093](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ecx2093/32/5623_2.png) [@ecx2093](https://discourse.julialang.org/u/ecx2093)\
**Post date:** [June 4, 2017, 8:56pm UTC](https://discourse.julialang.org/t/embedding-plots-in-gtk-jl/4085/2 "2017-06-04T20:56:38Z")

</div>

I haven’t actually embedded GR in gtk but I have seen this file over in the GR package examples folder. Maybe it will help point you in the right direction: [https://github.com/jheinen/GR.jl/blob/master/examples/gtk\_ex.jl](https://github.com/jheinen/GR.jl/blob/master/examples/gtk_ex.jl)

---

<div class="post-metadata">

**Author:** ![jonathanBieler](https://avatars.discourse-cdn.com/v4/letter/j/82dd89/32.png) [@jonathanBieler](https://discourse.julialang.org/u/jonathanBieler)\
**Post date:** [June 4, 2017, 8:59pm UTC](https://discourse.julialang.org/t/embedding-plots-in-gtk-jl/4085/3 "2017-06-04T20:59:29Z")

</div>

Immerse.jl does that via Gadfly.

[https://github.com/JuliaGraphics/Immerse.jl](https://github.com/JuliaGraphics/Immerse.jl)

It would be nice if it could support other plotting backends. I thought a bit about it at some point, but last time I tried GR I ran into some issues.

If the backend cannot draw on a GtkCanvas directly, you could also just copy an image on it.

---

<div class="post-metadata">

**Author:** ![piever](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/piever/32/1815_2.png) [@piever](https://discourse.julialang.org/u/piever)\
**Post date:** [June 4, 2017, 10:13pm UTC](https://discourse.julialang.org/t/embedding-plots-in-gtk-jl/4085/4 "2017-06-04T22:13:07Z")

</div>

> [@ecx2093](#):
>
> I have seen this file over in the GR package examples folder

The example GR file gives a segmentation fault, but maybe some variation of it can work, thanks for the link.

> [@jonathanBieler](#):
>
> If the backend cannot draw on a GtkCanvas directly, you could also just copy an image on it.

I was thinking about that option as well, is there a simple way to convert a plot to an image?

---

<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, 2017, 2:28am UTC](https://discourse.julialang.org/t/embedding-plots-in-gtk-jl/4085/5 "2017-06-05T02:28:25Z")

</div>

InspectDR.jl is a pure-Julia plotting solution that leverages the Cairo.jl & Gtk.jl packages to draw plots & build multi-plot GUIs respectively:

Link: [https://github.com/ma-laforge/InspectDR.jl](https://github.com/ma-laforge/InspectDR.jl)

I have not really published an API for integrating the InspectDR plot widget into external applications, but it is designed with the following layers:

- Cairo layer: Generates plots as images.
- GTK widget layer: Defines a GTK widget that can be integrated in a Gtk.jl applications.
- GTK application layer: What I assume most users would use.

To integrate a GTK widget in your own application, you could look at how `PlotWidget` objects are created/used in the following file:

Link: [https://github.com/ma-laforge/InspectDR.jl/blob/master/src/gtk\_top.jl](https://github.com/ma-laforge/InspectDR.jl/blob/master/src/gtk_top.jl)

Note that the GTK widget is not a simple plot image. It provides interactivity allowing one to pan/zoom, add “delta” markers, etc through mouse/key bindings.

Feel free to integrate with your own application - but please note that I have not put tons of effort defining how one manipulates the `PlotWidget` object. Its interface might need to change to allow for future improvements.

---

<div class="post-metadata">

**Author:** ![tobias.knopp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tobias.knopp/32/7551_2.png) [@tobias.knopp](https://discourse.julialang.org/u/tobias.knopp)\
**Post date:** [June 5, 2017, 11:54am UTC](https://discourse.julialang.org/t/embedding-plots-in-gtk-jl/4085/6 "2017-06-05T11:54:25Z")

</div>

I am using Winston.jl but InspectDR.jl seems to look quite good as well.
