Python 在qlistwidget中更改行后使用matplotlib打印

Python 在qlistwidget中更改行后使用matplotlib打印,python,matplotlib,pyqt,Python,Matplotlib,Pyqt,我想在单击行后绘制图表。信号已传输,但图表未绘制。但是如果我从MyPlot.\uuu init\uuu调用一个绘图函数(self.hist()),图表就会被绘制出来 我用这个作为例子,但它没有帮助 import sys from PyQt4 import QtGui from PyQt4 import QtCore from PyQt4.QtCore import QCoreApplication, Qt from PyQt4.QtGui import QListWidget, QListWid

我想在单击行后绘制图表。信号已传输,但图表未绘制。但是如果我从
MyPlot.\uuu init\uuu
调用一个绘图函数(
self.hist()
),图表就会被绘制出来

我用这个作为例子,但它没有帮助

import sys
from PyQt4 import QtGui
from PyQt4 import QtCore
from PyQt4.QtCore import QCoreApplication, Qt
from PyQt4.QtGui import QListWidget, QListWidgetItem, QApplication, QMessageBox
import matplotlib
import matplotlib.pyplot as plt
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.backends.backend_qt4agg import NavigationToolbar2QT as NavigationToolbar
from matplotlib.figure import Figure
import sqlite3
matplotlib.style.use('ggplot')
import pandas as pd
import numpy as np

# my plotting functions are in this class
class Myplot(FigureCanvas):
    def __init__(self, parent=None):
        self.fig = Figure()
        FigureCanvas.__init__(self, self.fig)
        #self.hist()    

#this and next functions should plot
    def compute_initial_figure(self):
        self.axes = self.fig.add_subplot(1,1,1)
        self.axes.hold(False)
        self.axes.plot(np.random.rand(400))
        self.draw()
    def hist(self):
        tm = pd.Series(np.random.randn(500), index=pd.date_range('1/1/2005', periods=500))
        self.axes = self.fig.add_subplot(1,1,1)
        self.axes.hold(False)
        tm = tm.cumsum()
        self.axes.plot(tm)
        self.draw()

#list with rows. I want to draw charts after clicking on them
class Panel (QtGui.QListWidget):
    def __init__(self, parent=None):
        QtGui.QListWidget.__init__(self)
        self.row1 = "COMMISSIONS & FEES"
        self.addItem(self.row1)
        row2 = "NET LIQUIDATING VALUE"
        self.addItem(row2)
        self.setFixedWidth(200)
        self.itemClicked.connect(self.Clicked)

#this function sends signal to the plotting functions
    def Clicked(self):
        mplot=Myplot()
        index=self.currentRow()
        if index == 0:
            print '0000'
            mplot.compute_initial_figure()
        if index == 1:
            print '1111'
            mplot.hist()

class MainWindow(QtGui.QMainWindow):
    def __init__(self):
        super(MainWindow, self).__init__()
        self.initUI()

    def initUI(self):
        #menu
        exitAction = QtGui.QAction(QtGui.QIcon('Stuff/exit.png'), '&Exit', self)        
        exitAction.setShortcut('Ctrl+Q')
        exitAction.setStatusTip('Exit application')
        exitAction.triggered.connect(QtGui.qApp.quit)

        menubar = self.menuBar()
        fileMenu = menubar.addMenu('&File')        

        self.statusBar().showMessage('Ready')
        self.showMaximized()
        self.setMinimumSize(600, 400)
        self.setWindowTitle('ESPA')
        self.setWindowIcon(QtGui.QIcon('Stuff/icon.png.'))

        #setup window widgets
        self.main_widget= QtGui.QWidget(self)
        #lines up widgets horizontally
        layout = QtGui.QHBoxLayout(self.main_widget)
        mp=Myplot(self.main_widget)
        p=Panel(self.main_widget)
        layout.addWidget(p)
        layout.addWidget(mp)
        self.main_widget.setFocus()

        self.setCentralWidget(self.main_widget)

if __name__ == '__main__':
    app = QtGui.QApplication(sys.argv)
    mw = MainWindow()
    mw.show()
    sys.exit(app.exec_())