带有matplotlib数字的Qgridlayout

时间:2015-04-19 15:23:52

标签: python matplotlib pyqt pyqt4

我正在尝试使用实时更新的matplotlib数字创建应用程序。因此我一起使用PyQt4巫婆matplotlib。我对Qmainwidget中绘制的数字大小有疑问。我希望一个图(gauge1)比另一个图(dc)小三倍(水平)。根据文档(如果我很了解它们)这应该给出正确的大小:

    self.main_widget = QtGui.QWidget(self)

    layout=QtGui.QGridLayout(self.main_widget)
    layout.setSpacing(20)
    layout.expandingDirections()

    time=Datetime() 
    dc = Plotgraph()
    gauge1=Gauge()
    #===ADD_WIDGET: at start-row,start-column, #rows , #colums======
    layout.addWidget(gauge1,1,1,2,1)
    layout.addWidget(dc,3,1,5,1)

然而,Qwidget gauge1总是比另一个大。我想使用QgridLayout,因为应用程序必须在不同大小的屏幕上工作。 我还添加了两个编写的类的代码,以防他们的错误。我想我没有以正确的方式使用Qgridlayout。

Plotgraph类的代码:

class MyMplCanvas(FigureCanvas):
    """Ultimately, this is a QWidget (as well as a FigureCanvasAgg, etc.)."""
    def __init__(self, parent=None):
        fig = Figure()
        self.axes = fig.add_subplot(111,autoscale_on=True)
        self.axes.set_ybound(lower=0,upper=None)
        FigureCanvas.__init__(self, fig)
        self.setParent(parent)
        FigureCanvas.updateGeometry(self)

    def compute_initial_figure(self):
        pass

class Plotgraph(MyMplCanvas):
    def __init__(self,parent=None):
        MyMplCanvas.__init__(self)
        self.axes.xaxis_date()
        self.xdata=[]
        self.ydata=[]
        self.formater = md.DateFormatter(' %H:%M:%S')
        self.compute_initial_figure()
        self.timeClear=0
        self.update_figure()
        timer=QtCore.QTimer(self)
        timer.timeout.connect(self.update_figure)
        timer.start(5000)
    def compute_initial_figure(self):
        pass
    def update_figure(self): 
        .....

Gauge类的代码:

class MyMplCanvas(FigureCanvas):
    """Ultimately, this is a QWidget (as well as a FigureCanvasAgg, etc.)."""
    def __init__(self, parent=None):
        self.fig = Figure()
        self.axes = self.fig.add_subplot(111,autoscale_on=True)
        self.axes.axis('off')
        self.fig.tight_layout()       

        FigureCanvas.__init__(self, self.fig)
        self.setParent(parent)

        FigureCanvas.updateGeometry(self)

    def compute_initial_figure(self):
       pass

class Gauge(MyMplCanvas):
    def __init__(self,meter,parent=None):
        MyMplCanvas.__init__(self)

        self.compute_initial_figure()            


        timer=QtCore.QTimer(self)
        timer.timeout.connect(self.update_figure)
        timer.start(5000)
        self.update_figure()
    def compute_initial_figure(self):
        pass

    def update_figure(self):         
       ....

0 个答案:

没有答案