2

I am currently trying to build a simple app that includes some pylab figures. I just started to use quickly and I am concerned about some import issues. That is, none of the matplotlib backends will be able to work.

More specifically, if any of the following import statements is uncommented in my main file, then quickly will fail to run the app

#from matplotlib.backends.backend_gtk import FigureCanvasGTK as FigureCanvas
#from matplotlib.backends.backend_gtkagg import FigureCanvasGTKAgg as FigureCanvas
#from matplotlib.backends.backend_gtkcairo import FigureCanvasGTKCairo as FigureCanvas

so there is no way I can embed a plot.

Here is the output of quickly run if the backend_gtk is uncommented

/usr/lib/python2.7/dist-packages/gobject/constants.py:24: Warning: g_boxed_type_register_static: assertion `g_type_from_name (name) == 0' failed   import gobject._gobject 
/usr/lib/python2.7/dist-packages/gtk-2.0/gtk/__init__.py:40: Warning: specified class size for type `PyGtkGenericCellRenderer' is smaller than the parent type's `GtkCellRenderer' class size   from gtk import
_gtk 
/usr/lib/python2.7/dist-packages/gtk-2.0/gtk/__init__.py:40: Warning: g_type_get_qdata: assertion `node != NULL' failed   from gtk import _gtk

Any idea of what could solve the problem? Do you need more information?

3
  • 1
    Question closed during answering... Anyway: you'll need atleast version 1.2.0 of matplotlab, which can be installed by pip if it's not in your repository. Then use the GTK3 backends, for example: matplotlib.org/examples/user_interfaces/embedding_in_gtk3.html
    – Timo
    Mar 1, 2014 at 11:08
  • Developing GUI apps in Python that run on Ubuntu is widely treated as on-topic on Ask Ubuntu, though I'm not aware of any strong community consensus either way on the issue. This question certainly seems on-topic since it's about Quickly, though the answer is not Quickly-specific. This is answered in a comment and that comment would better be posted as an answer. I've voted to reopen this, though I understand if some people disagree. Mar 2, 2014 at 18:37
  • @Timo The question is now reopened. Can you add an answer?
    – Seth
    Mar 2, 2014 at 19:32

1 Answer 1

1

You'll need atleast version 1.2.0 of matplotlib and then use the GTK3 backends.

Example taken from http://matplotlib.org/examples/user_interfaces/embedding_in_gtk3.html

#!/usr/bin/env python
"""
demonstrate adding a FigureCanvasGTK3Agg widget to a Gtk.ScrolledWindow
using GTK3 accessed via pygobject
"""

from gi.repository import Gtk

from matplotlib.figure import Figure
from numpy import arange, sin, pi
from matplotlib.backends.backend_gtk3agg import FigureCanvasGTK3Agg as FigureCanvas

win = Gtk.Window()
win.connect("delete-event", Gtk.main_quit )
win.set_default_size(400,300)
win.set_title("Embedding in GTK")

f = Figure(figsize=(5,4), dpi=100)
a = f.add_subplot(111)
t = arange(0.0,3.0,0.01)
s = sin(2*pi*t)
a.plot(t,s)

sw = Gtk.ScrolledWindow()
win.add (sw)
# A scrolled window border goes outside the scrollbars and viewport
sw.set_border_width (10)

canvas = FigureCanvas(f)  # a Gtk.DrawingArea
canvas.set_size_request(800,600)
sw.add_with_viewport (canvas)

win.show_all()
Gtk.main()

Note: Ubuntu 12.04 doesn't have Matplotlib 1.2.0 in the repository, but it is installable through pip:

sudo pip install matplotlib

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .