与gtkcairo后端有限的matplotlib功能

时间:2014-11-17 21:04:13

标签: python matplotlib gtk

我正在开发一个应用程序,它将matplotlib嵌入到python和gtk2程序中,并将gtkcairo后端用于matplotlib。我成功使用axes.plot,但如果我尝试使用像scatter()这样的东西来制作色彩图,或者使用像套索这样的交互式工具,我会收到错误。发生错误时会在问题详细信息中报告:

Most Recent Project: C:\Users\Documents\p\p.aprojx 
Platform: AMD64
Traceback (most recent call last):
  File "C:\Users\Work\components\win64\lib\python2.7\matplotlib\backends\backend_gtk.py", line 435, in expose_event
    self._render_figure(self._pixmap, w, h)
  File "C:\Users\Work\components\win64\lib\python2.7\matplotlib\backends\backend_gtk.py", line 423, in _render_figure
    self.figure.draw (self._renderer)
  File "C:\Users\Work\components\win64\lib\python2.7\matplotlib\artist.py", line 55, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "C:\Users\Work\components\win64\lib\python2.7\matplotlib\figure.py", line 1034, in draw
    func(*args)
  File "C:\Users\Work\components\win64\lib\python2.7\matplotlib\artist.py", line 55, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "C:\Users\Work\components\win64\lib\python2.7\matplotlib\axes.py", line 2086, in draw
    a.draw(renderer)
  File "C:\Users\Work\components\win64\lib\python2.7\matplotlib\artist.py", line 55, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "C:\Users\Work\components\win64\lib\python2.7\matplotlib\collections.py", line 717, in draw
    for x in self._sizes]
TypeError: Not implemented for this type

我想知道问题是什么,以及我能做些什么。目前我认为gtkcairo是问题所在,或者使用gtk2而不是3,但我不确定目前是否更改其中任何一项都是可行的。

这是正常工作的代码,但是如果我将plot()更改为scatter()或其他任何我遇到错误。

def plot(self, x, y, xlabel, ylabel, semilogX = False, semilogY = False, plot_circles = False):
    self._figure.clear()
    axes = matplotlib.axes.Subplot(self._figure, 111)
    self._figure.add_axes(axes)

    if semilogX:
        axes.set_xscale('log')
    if semilogY:
        axes.set_yscale('log')
    if plot_circles:
        self.pts = axes.plot(x, y, 'o', c='blue', alpha=0.4)
    else:
        self.pts = axes.plot(x, y, ',', c='blue')
    axes.set_xlabel(xlabel)

    # the extra space is a hack for what appears to be a bug in the GTK backend where it draws
    # the y label horizontally, then rotates it to be vertical, but it does not figure out the
    # extent of the text correctly so leaves the trailing edge of a character (e.g. the leg of
    # an 'h' behind) - the ' ' means the left behind object is not very visible...sigh
    axes.set_ylabel(ylabel + ' ')
    configure_axes(axes, True)
    self.canvas.show()

0 个答案:

没有答案