GTKAgg throwing an exception

Hi matplotlib-users,

I decided to try to make some plots that I have previously made in png
format using the Agg backend in jpeg format using the GTKAgg backend
(which I guess is the one I should use for this). Unfortunately my
script exits with an error. I have therefore created a simple test
script (test.py) that illustrates the problem (at least on my
computer):

import matplotlib
from matplotlib.backends.backend_gtkagg import FigureCanvasGTKAgg as
FigureCanvas

fig = matplotlib.figure.Figure(dpi=100)
canvas = FigureCanvas(fig)
fig.savefig('test.jpg')

When I run it I get:

$ python test.py
/usr/lib/python2.5/site-packages/matplotlib/backends/backend_gtk.py:357:
GtkWarning: gtk_widget_realize: assertion `GTK_WIDGET_ANCHORED
(widget) || GTK_IS_INVISIBLE (widget)' failed
  gtk.DrawingArea.realize(self)
/usr/lib/python2.5/site-packages/matplotlib/backends/backend_gtk.py:360:
GtkWarning: gdk_pixmap_new: assertion `(drawable != NULL) || (depth !=
-1)' failed
  pixmap = gdk.Pixmap (self.window, width, height)
Traceback (most recent call last):
  File "test.py", line 6, in <module>
    fig.savefig('test.jpg')
  File "/usr/lib/python2.5/site-packages/matplotlib/figure.py", line
964, in savefig
    self.canvas.print_figure(*args, **kwargs)
  File "/usr/lib/python2.5/site-packages/matplotlib/backend_bases.py",
line 1310, in print_figure
    **kwargs)
  File "/usr/lib/python2.5/site-packages/matplotlib/backends/backend_gtk.py",
line 347, in print_jpeg
    return self._print_image(filename, 'jpeg')
  File "/usr/lib/python2.5/site-packages/matplotlib/backends/backend_gtk.py",
line 360, in _print_image
    pixmap = gdk.Pixmap (self.window, width, height)
RuntimeError: could not create GdkPixmap object

I am using matplotlib 0.98.3, pygtk 2.14.0. My system is a Linux Ubuntu:

$ uname -a
Linux <blanket out> #1 SMP Wed Aug 20 18:39:13 UTC 2008 i686 GNU/Linux

Does anyone know what is wrong?

Best regards,
Jesper

I can't make much sense of this. You don't plot anything and don't use
canvas.

This code works:

import matplotlib
matplotlib.use('GTKAgg')
from matplotlib import pyplot
pyplot.plot([0, 1, 2, 3], [0, 1, 2, 3])
fig = pyplot.gcf()
fig.savefig('test.jpg')

But I don't know how to set the dpi value this way. I tried to use the
OO API but no success.

Goyo

···

El dom, 12-10-2008 a las 23:45 +0200, Jesper Larsen escribió:

Hi matplotlib-users,

I decided to try to make some plots that I have previously made in png
format using the Agg backend in jpeg format using the GTKAgg backend
(which I guess is the one I should use for this). Unfortunately my
script exits with an error. I have therefore created a simple test
script (test.py) that illustrates the problem (at least on my
computer):

import matplotlib
from matplotlib.backends.backend_gtkagg import FigureCanvasGTKAgg as
FigureCanvas

fig = matplotlib.figure.Figure(dpi=100)
canvas = FigureCanvas(fig)
fig.savefig('test.jpg')

When I run it I get:

$ python test.py
/usr/lib/python2.5/site-packages/matplotlib/backends/backend_gtk.py:357:
GtkWarning: gtk_widget_realize: assertion `GTK_WIDGET_ANCHORED
(widget) || GTK_IS_INVISIBLE (widget)' failed
  gtk.DrawingArea.realize(self)
/usr/lib/python2.5/site-packages/matplotlib/backends/backend_gtk.py:360:
GtkWarning: gdk_pixmap_new: assertion `(drawable != NULL) || (depth !=
-1)' failed
  pixmap = gdk.Pixmap (self.window, width, height)
Traceback (most recent call last):
  File "test.py", line 6, in <module>
    fig.savefig('test.jpg')
  File "/usr/lib/python2.5/site-packages/matplotlib/figure.py", line
964, in savefig
    self.canvas.print_figure(*args, **kwargs)
  File "/usr/lib/python2.5/site-packages/matplotlib/backend_bases.py",
line 1310, in print_figure
    **kwargs)
  File "/usr/lib/python2.5/site-packages/matplotlib/backends/backend_gtk.py",
line 347, in print_jpeg
    return self._print_image(filename, 'jpeg')
  File "/usr/lib/python2.5/site-packages/matplotlib/backends/backend_gtk.py",
line 360, in _print_image
    pixmap = gdk.Pixmap (self.window, width, height)
RuntimeError: could not create GdkPixmap object

I am using matplotlib 0.98.3, pygtk 2.14.0. My system is a Linux Ubuntu:

$ uname -a
Linux <blanket out> #1 SMP Wed Aug 20 18:39:13 UTC 2008 i686 GNU/Linux

Does anyone know what is wrong?

Best regards,
Jesper

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Goyo wrote:

I can't make much sense of this. You don't plot anything and don't use
canvas.

This code works:

import matplotlib
matplotlib.use('GTKAgg')
from matplotlib import pyplot
pyplot.plot([0, 1, 2, 3], [0, 1, 2, 3])
fig = pyplot.gcf()
fig.savefig('test.jpg')

fig.savefig('test.jpg', dpi=150) # or whatever dpi you want

If you are only using savefig, not plotting to the screen, then you might as well use the agg backend, not the gtkagg.

Eric

···

But I don't know how to set the dpi value this way. I tried to use the
OO API but no success.

Goyo

El dom, 12-10-2008 a las 23:45 +0200, Jesper Larsen escribió:

Hi matplotlib-users,

I decided to try to make some plots that I have previously made in png
format using the Agg backend in jpeg format using the GTKAgg backend
(which I guess is the one I should use for this). Unfortunately my
script exits with an error. I have therefore created a simple test
script (test.py) that illustrates the problem (at least on my
computer):

import matplotlib
from matplotlib.backends.backend_gtkagg import FigureCanvasGTKAgg as
FigureCanvas

fig = matplotlib.figure.Figure(dpi=100)
canvas = FigureCanvas(fig)
fig.savefig('test.jpg')

When I run it I get:

$ python test.py
/usr/lib/python2.5/site-packages/matplotlib/backends/backend_gtk.py:357:
GtkWarning: gtk_widget_realize: assertion `GTK_WIDGET_ANCHORED
(widget) || GTK_IS_INVISIBLE (widget)' failed
  gtk.DrawingArea.realize(self)
/usr/lib/python2.5/site-packages/matplotlib/backends/backend_gtk.py:360:
GtkWarning: gdk_pixmap_new: assertion `(drawable != NULL) || (depth !=
-1)' failed
  pixmap = gdk.Pixmap (self.window, width, height)
Traceback (most recent call last):
  File "test.py", line 6, in <module>
    fig.savefig('test.jpg')
  File "/usr/lib/python2.5/site-packages/matplotlib/figure.py", line
964, in savefig
    self.canvas.print_figure(*args, **kwargs)
  File "/usr/lib/python2.5/site-packages/matplotlib/backend_bases.py",
line 1310, in print_figure
    **kwargs)
  File "/usr/lib/python2.5/site-packages/matplotlib/backends/backend_gtk.py",
line 347, in print_jpeg
    return self._print_image(filename, 'jpeg')
  File "/usr/lib/python2.5/site-packages/matplotlib/backends/backend_gtk.py",
line 360, in _print_image
    pixmap = gdk.Pixmap (self.window, width, height)
RuntimeError: could not create GdkPixmap object

I am using matplotlib 0.98.3, pygtk 2.14.0. My system is a Linux Ubuntu:

$ uname -a
Linux <blanket out> #1 SMP Wed Aug 20 18:39:13 UTC 2008 i686 GNU/Linux

Does anyone know what is wrong?

Best regards,
Jesper

Well yes...

import matplotlib
matplotlib.use('GTKAgg')
from matplotlib import pyplot
fig = pyplot.figure(dpi=100)
ax = fig.add_subplot('111')
ax.plot([1, 2, 3], [1, 2, 3])
fig.savefig('test.jpg')

But changing the dpi value has no effect so maybe I'm missing something.

Goyo

···

El lun, 13-10-2008 a las 00:41 +0200, Goyo escribió:

But I don't know how to set the dpi value this way. I tried to use the
OO API but no success.

Goyo wrote:

···

El lun, 13-10-2008 a las 00:41 +0200, Goyo escribió:

But I don't know how to set the dpi value this way. I tried to use the
OO API but no success.

Well yes...

import matplotlib
matplotlib.use('GTKAgg')
from matplotlib import pyplot
fig = pyplot.figure(dpi=100)
ax = fig.add_subplot('111')
ax.plot([1, 2, 3], [1, 2, 3])
fig.savefig('test.jpg')

But changing the dpi value has no effect so maybe I'm missing something.

The figure dpi is irrelevant when saving the figure; only the dpi specified in the savefig command matters for that. This is inherently confusing. I'm thinking about a solution, but haven't tried it yet.

Eric

Hi Eric and Goyo

Thanks for your comments and thanks for your working example, Goyo.

Eric Firing <efiring@...202...>:

If you are only using savefig, not plotting to the screen, then you might as
well use the agg backend, not the gtkagg.

I have previously used the agg backend without any problems. The
reason I am switching to GTK(Agg) is because I would like to save some
of my plots in jpeg (which only the GTK backend supports). In some
tests that I have made (manually converting png plots to jpeg with
PIL) it seems like this will result in much smaller plots that are
still in good quality. My application serves plots over the internet
so file size is quite important.

Best regards,
Jesper