Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

matplotlib figure in GTK with tools

When I create a figure in matplotlib I get these nice tools to move the graph around zoom in and out ect. However the only way I know how to put the figure into a GTK GUI is by converting it to a drawing area. When I convert I obviously lose the nice tools.

Is there a better way of putting a matplotlib figure into a GTK GUI so I can keep the tools?

with tools

without tools

like image 323
user2327814 Avatar asked Feb 23 '26 09:02

user2327814


1 Answers

This is an example, hope it helps:

from matplotlib.figure import Figure as F
from matplotlib.backends.backend_gtkagg import FigureCanvasGTKAgg as FC
from matplotlib.backends.backend_gtkagg import NavigationToolbar2GTKAgg as NT

import gtk

fig = F()
ax = fig.add_subplot(111)
ax.plot(range(10),range(10))

main = gtk.Window()
main.set_default_size(800,600)
main.connect("destroy", gtk.main_quit)
box = gtk.VBox()
main.add(box)

fc = FC(fig)
box.pack_start(fc)
nt = NT(fc, main)
box.pack_start(nt, expand=False, fill=False)
main.show_all()
gtk.main()
like image 167
Alvaro Fuentes Avatar answered Feb 25 '26 00:02

Alvaro Fuentes



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!