Answer the question
In order to leave comments, you need to log in
In pyqt, plotting different matplotlib plots after row clicks?
I want to build different graphics after clicks on acc. rows in QListWidget. The signal is transmitted via connect, but the graph is not built (nothing happens), and if you place a call to the graph function (self.hist()) in __init__ , then the graph is built, but if you try to build it through the signal, then no :/
part of the code, related to this problem
class Myplot(FigureCanvas):
def __init__(self, parent=None):
self.fig = Figure()
FigureCanvas.__init__(self, self.fig)
# self.hist()
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))
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)
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)
def Clicked(self):
mplot=Myplot()
index=self.currentRow()
if index == 0:
print '0000'
mplot.compute_initial_figure()
if index == 1:
mplot.hist()
Answer the question
In order to leave comments, you need to log in
I didn’t find anything else, except how to combine both classes into one, that’s the only way it worked
class Myplot(QtGui.QWidget):
def __init__(self, parent=None):
super(Myplot, self).__init__(parent)
# a figure instance to plot on
self.figure = plt.figure()
# this is the Canvas Widget that displays the `figure`
# it takes the `figure` instance as a parameter to __init__
self.canvas = FigureCanvas(self.figure)
self.mylist=QListWidget(self)
row1="COMMISSIONS & FEES"
self.mylist.addItem(row1)
row2="NET LIQUIDATING VALUE"
self.mylist.addItem(row2)
self.mylist.setFixedWidth(200)
self.mylist.itemClicked.connect(self.Clicked)
# set the layout
minlayout = QtGui.QHBoxLayout()
minlayout.addWidget(self.mylist)
minlayout.addWidget(self.canvas)
self.setLayout(minlayout)
# self.hist()
def compute_initial_figure(self):
# random data
xdata = [random.random() for i in range(10)]
# create an axis
ax = self.figure.add_subplot(111)
# discards the old graph
ax.hold(False)
# plot data
ax.plot(xdata)
# refresh canvas
self.canvas.draw()
def hist(self):
tm = pd.Series(np.random.randn(500), index=pd.date_range('1/1/2005', periods=500))
tm = tm.cumsum()
ax = self.figure.add_subplot(111)
ax.hold(False)
ax.plot(tm)
self.canvas.draw()
def Clicked(self):
index=self.mylist.currentRow()
if index == 0:
print '0000'
self.compute_initial_figure()
if index == 1:
print '1111'
self.hist()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question