简体   繁体   English

pyqt中具有matplotlib的loglog图-轴消失

[英]loglog plot with matplotlib in pyqt - axes disappear

I am trying to use matplotlib plotting library inside PyQt4 to plot loglog plot. 我正在尝试在PyQt4内使用matplotlib绘图库来绘制loglog图。 I have added two lines of code in the class: 我在该类中添加了两行代码:

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

but then axes disappeared and got an error below. 但是轴消失了,下面出现了一个错误。 I would like to ask you how can I use matplotlib library inside PyQt4 to plot loglot plot. 我想问你如何在PyQt4中使用matplotlib库来绘制loglot图。 As seen in the figure below. 如下图所示。 Python 2.7.5, matplotlib 1.3.0, PyQt 4.10.4 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'

This is probably because your x-range includes 0 . 这可能是因为您的x范围包含0 True log scales can't reach 0. If you want to include 0, you'll need to use 'semilog' instead. 真实的对数比例不能达到0。如果要包括0,则需要使用'semilog'

Judging from the error message you're getting, I'd bet you're using a fairly old release of matplotlib? 从收到的错误消息来看,我敢打赌您使用的是matplotlib的较旧版本? For what it's worth, in newer versions, including 0 will cause the scale to be automatically changed to semilog instead of log . 就其价值而言,在较新的版本中,包括0将导致小数semilog自动更改为semilog而不是log

Either way, try specifying a semilog scale, and see if that helps. 无论哪种方式,请尝试指定半对数刻度,看看是否有帮助。 Eg 例如

self.axes.set(xscale='semilog', yscale='semilog')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM