Crash using twin axis label with PyGTK

I'm playing around with using Matplotlib in my PyGTK app, and keep
triggering a crash. I've narrowed it down to this bit of code:

···

----
import pygtk
import gtk

from matplotlib.backends.backend_gtk import FigureCanvasGTK
from matplotlib.figure import Figure

def TestGraph(one, two, three):
    figure = Figure()
    ax1 = figure.add_subplot(111)
    ax2 = ax1.twinx()
    # Remove this line and it all works:
    ax2.set_ylabel("Y")
    return FigureCanvasGTK(figure)

graph = TestGraph(
                [[0,1,2],[0.1, 0.2, 0.35]],
                [[0,1,2],[9,22,29]],
                [[0,1,2],[10,20,30]])

window = gtk.Window()
window.add(graph)

def destroy(widget, data=None):
    gtk.main_quit()

window.connect('destroy', destroy)
window.show_all()
gtk.main()
----

Running this gives me:
$ Projects/python-virt/bin/python mpltest.py
The program 'mpltest.py' received an X Window System error.
This probably reflects a bug in the program.
The error was 'BadMatch (invalid parameter attributes)'.
  (Details: serial 553 error_code 8 request_code 73 minor_code 0)
  (Note to programmers: normally, X errors are reported asynchronously;
   that is, you will receive the error a while after causing it.
   To debug your program, run it with the --sync command line
   option to change this behavior. You can then get a meaningful
   backtrace from your debugger if you break on the gdk_x_error() function.)
$

Am I doing something obviously wrong? (Apart from the lack of plots, I
mean... I removed them because they didn't change the behaviour.)

This is under...
Debian Squeeze/Wheezy/Sid
Python: 2.6.5
Matplotlib: SVN r8988
GTK: 2.20.1
PyGTK: 2.17.0

Cheers,
Jason

Jason Heeris, on 2011-04-21 12:23, wrote:

I'm playing around with using Matplotlib in my PyGTK app, and keep
triggering a crash. I've narrowed it down to this bit of code:

...

Am I doing something obviously wrong? (Apart from the lack of plots, I
mean... I removed them because they didn't change the behaviour.)

Thanks for the report, Jason. It's a bug - could you please file
a bug report, so we can keep track of it?

It looks like this gets triggered by the fact that the ylabel is
being clipped. I don't have time to look into this further, but
here are two workaround for you. Either do:

  figure.subplotpars.right=.8 # make smaller if still crashes

or if it's an option, use gtkagg, which doesn't suffer from the crash.

  from matplotlib.backends.backend_gtkagg import FigureCanvasGTKAgg
as FigureCanvasGTK

best,

···

--
Paul Ivanov
314 address only used for lists, off-list direct email at:
http://pirsquared.org | GPG/PGP key id: 0x0F3E28F7

Thanks for the report, Jason. It's a bug - could you please file
a bug report, so we can keep track of it?

Will do, thanks for the workarounds :slight_smile:

or if it's an option, use gtkagg, which doesn't suffer from the crash.

from matplotlib.backends.backend_gtkagg import FigureCanvasGTKAgg
as FigureCanvasGTK

Just out of interest, what's the difference between GTK and GTKAgg?

— Jason

···

On 22 April 2011 03:56, Paul Ivanov <pivanov314@...287...> wrote:

Jason Heeris, on 2011-04-23 00:29, wrote:

> Thanks for the report, Jason. It's a bug - could you please file
> a bug report, so we can keep track of it?

Will do, thanks for the workarounds :slight_smile:

> or if it's an option, use gtkagg, which doesn't suffer from the crash.
>
> from matplotlib.backends.backend_gtkagg import FigureCanvasGTKAgg
> as FigureCanvasGTK

Just out of interest, what's the difference between GTK and GTKAgg?

The FAQ has a nice summary:

    The canonical renderer for user interfaces is Agg which uses the
    Anti-Grain Geometry C++ library to make a raster (pixel) image of
    the figure. All of the user interfaces can be used with agg
    rendering, eg WXAgg, GTKAgg, QTAgg, TkAgg, CocoaAgg. In addition,
    some of the user interfaces support other rendering engines. For
    example, with GTK, you can also select GDK rendering (backend
    GTK) or Cairo rendering (backend GTKCairo).

http://matplotlib.sourceforge.net/faq/installing_faq.html#what-is-a-backend

There are also two tables at the end of that answer which list
the renderers, and the user interface + renderer combinations.

best,

···

On 22 April 2011 03:56, Paul Ivanov <pivanov314@...287...> wrote:

--
Paul Ivanov
314 address only used for lists, off-list direct email at:
http://pirsquared.org | GPG/PGP key id: 0x0F3E28F7

Jason Heeris, on 2011-04-23 00:29, wrote:

Thanks for the report, Jason. It's a bug - could you please file
a bug report, so we can keep track of it?

Will do, thanks for the workarounds :slight_smile:

or if it's an option, use gtkagg, which doesn't suffer from the crash.

  from matplotlib.backends.backend_gtkagg import FigureCanvasGTKAgg
as FigureCanvasGTK

Just out of interest, what's the difference between GTK and GTKAgg?

The FAQ has a nice summary:

     The canonical renderer for user interfaces is Agg which uses the
     Anti-Grain Geometry C++ library to make a raster (pixel) image of
     the figure. All of the user interfaces can be used with agg
     rendering, eg WXAgg, GTKAgg, QTAgg, TkAgg, CocoaAgg. In addition,
     some of the user interfaces support other rendering engines. For
     example, with GTK, you can also select GDK rendering (backend
     GTK) or Cairo rendering (backend GTKCairo).

http://matplotlib.sourceforge.net/faq/installing_faq.html#what-is-a-backend

There are also two tables at the end of that answer which list
the renderers, and the user interface + renderer combinations.

Note that the gtk and wx backends (that is, no Agg) are not recommended. They are not well maintained and may have various limitations and bugs. Their only potential advantage, as far as I know, is that they involve less network traffic when working remotely via X.

Eric

···

On 04/22/2011 06:47 AM, Paul Ivanov wrote:

On 22 April 2011 03:56, Paul Ivanov<pivanov314@...287...> wrote:

best,