【发布时间】:2015-01-05 08:21:37
【问题描述】:
我正在尝试使用 PyQt4 中的 matplotlib 绘图库来绘制 loglog 图。我在类中添加了两行代码:
class MyStaticMplCanvas(MyMplCanvas):
"""Simple canvas with a sine plot."""
def compute_initial_figure(self):
t = arange(0.0, 3.0, 0.01)
s = abs((t * 1E+1) * sin(2 * pi * t) + 1E1)
self.axes.plot(t, s)
self.axes.set_yscale('log') #added code
self.axes.set_xscale('log') #added code
但随后轴消失并在下方出现错误。我想问你如何使用 PyQt4 中的 matplotlib 库来绘制 loglot 图。如下图所示。 Python 2.7.5、matplotlib 1.3.0、PyQt 4.10.4
Traceback (most recent call last):
File "C:\Python27\Lib\site-packages\matplotlib\backends\backend_qt4.py", line 299, in resizeEvent
self.draw()
File "C:\Python27\Lib\site-packages\matplotlib\backends\backend_qt4agg.py", line 148, in draw
FigureCanvasAgg.draw(self)
File "C:\Python27\Lib\site-packages\matplotlib\backends\backend_agg.py", line 451, in draw
self.figure.draw(self.renderer)
File "C:\Python27\Lib\site-packages\matplotlib\artist.py", line 54, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "C:\Python27\Lib\site-packages\matplotlib\figure.py", line 1034, in draw
func(*args)
File "C:\Python27\Lib\site-packages\matplotlib\artist.py", line 54, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "C:\Python27\Lib\site-packages\matplotlib\axes.py", line 2086, in draw
a.draw(renderer)
File "C:\Python27\Lib\site-packages\matplotlib\artist.py", line 54, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "C:\Python27\Lib\site-packages\matplotlib\axis.py", line 1093, in draw
renderer)
File "C:\Python27\Lib\site-packages\matplotlib\axis.py", line 1042, in _get_tick_bboxes
extent = tick.label1.get_window_extent(renderer)
File "C:\Python27\Lib\site-packages\matplotlib\text.py", line 754, in get_window_extent
bbox, info, descent = self._get_layout(self._renderer)
File "C:\Python27\Lib\site-packages\matplotlib\text.py", line 329, in _get_layout
ismath=ismath)
File "C:\Python27\Lib\site-packages\matplotlib\backends\backend_agg.py", line 210, in get_text_width_height_descent
self.mathtext_parser.parse(s, self.dpi, prop)
File "C:\Python27\Lib\site-packages\matplotlib\mathtext.py", line 3009, in parse
self.__class__._parser = Parser()
File "C:\Python27\Lib\site-packages\matplotlib\mathtext.py", line 2193, in __init__
- ((lbrace + float_literal + rbrace)
TypeError: unsupported operand type(s) for +: 'NoneType' and 'NoneType'
【问题讨论】:
标签: python matplotlib pyqt pyqt4