Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple Plots in Matplotlib Widget

I have designed a relatively large application but I am facing a problem in implementing the Matplotlibwidget graphs. This is the snippet of code where I am handling the graph.

The following code only plots the latest plot that of x2 and y2.

Note: here self.GraphWidget is a MatplotlibWidget object implemented using QtDesigner

def Toggled(self,CD):

    self.GraphWidget.axes.plot(self.x1,self.y1,label='plot1')
    self.GraphWidget.axes.plot(self.x2,self.y2,label='plot2')        

    self.GraphWidget.axes.set_xscale('log')

    self.GraphWidget.legend()
    self.GraphWidget.draw()

The following code (see below) plots both curves on the graph but I'd rather use the above method so that I can give individual labels etc to each curve:

def Toggled(self,CD):

    self.GraphWidget.axes.plot(self.x1,self.y1,self.x2,self.y2)


    self.GraphWidget.axes.set_xscale('log')

    self.GraphWidget.legend()
    self.GraphWidget.draw()
like image 242
Raj Vora Avatar asked Aug 13 '26 14:08

Raj Vora


1 Answers

Try explicitly setting hold:

self.GraphWidget.axes.hold(True)
self.GraphWidget.axes.plot(self.x1,self.y1,label='plot1')
self.GraphWidget.axes.plot(self.x2,self.y2,label='plot2')  
like image 115
Viktor Kerkez Avatar answered Aug 16 '26 04:08

Viktor Kerkez