Hi,

There is some sample of integration without comments (sorry).
'-' and '+' buttons increases and decreases dynamic matplotlib canvas.
Original idea taken from:
http://matplotlib.org/examples/user_interfaces/embedding_in_qt4.html).
I think that at the end you need to convert your Qt designer parts as
described in
http://stackoverflow.com/questions/18429452/convert-pyqt-ui-to-python and
then re-integrate it.

Cheers,
Vasilije

On Thu, Feb 9, 2017 at 5:02 AM, Aquiles J. <[email protected]> wrote:

> Hello,
>
> I want to design a GUI with QT designer that includes 3 plots:
>
> 1) Realtime plotting from COM port using PyQtGraph.
> 2) A 'screenshot' plot of the 1st one, but used in Matplotlib.
> 3) Another matplotlib plot that performs additional analysis on the graph
> presented in point 2.
>
> Is it possible to combine these 3 plots in a GUI? Has anyone else tried it
> before? I'd use PyQtGraph for everything, but there's some interactive
> features of Matplotlib I need that I'm not sure PyQtGraph can do at the
> moment (handling events, point selection, adding markers, erasing those
> updates, start over).
>
> Thanks for your time!
>
> --
> You received this message because you are subscribed to the Google Groups
> "pyqtgraph" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/pyqtgraph/ddd7a491-ae9e-44b2-8e81-63657028af7a%40googlegroups.com
> <https://groups.google.com/d/msgid/pyqtgraph/ddd7a491-ae9e-44b2-8e81-63657028af7a%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"pyqtgraph" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/pyqtgraph/CAD_qyJp36rt0QQWLgSzsRZCZbcdhuQDuARrcAUJ%2BR6PSMsQGcA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
# matplotlib and pyqtpgraph integration example by Vasilije Mehandzic
# based on embedding_in_qt4.py --- Simple Qt4 application embedding matplotlib 
canvases
# http://matplotlib.org/examples/user_interfaces/embedding_in_qt4.html
import sys
import os
import pyqtgraph
import matplotlib
import numpy

from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas

class MyMplCanvas(FigureCanvas):
    def __init__(self, parent=None, width=5, height=4, dpi=100):
        fig = matplotlib.figure.Figure(figsize=(width, height), dpi=dpi)
        self.axes = fig.add_subplot(111)

        self.compute_initial_figure()  

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

        FigureCanvas.setSizePolicy(self, pyqtgraph.QtGui.QSizePolicy.Expanding, 
pyqtgraph.QtGui.QSizePolicy.Expanding)
        FigureCanvas.updateGeometry(self)

    def compute_initial_figure(self):
        pass


class MyStaticMplCanvas(MyMplCanvas):
    def compute_initial_figure(self):
        t = numpy.arange(0.0, 3.0, 0.01)
        s = numpy.sin(2*numpy.pi*t)
        self.axes.plot(t, s)


class MyDynamicMplCanvas(MyMplCanvas):
    def __init__(self, *args, **kwargs):
        MyMplCanvas.__init__(self, *args, **kwargs)
        self.b1_clicked = False
        self.b2_clicked = False
        self.maxn = 10
        timer = pyqtgraph.Qt.QtCore.QTimer(self)
        timer.timeout.connect(self.update_figure)
        timer.start(100)

    def compute_initial_figure(self):
        self.axes.plot([0, 1, 2, 3], [1, 2, 0, 4], 'r')

    def update_figure(self):        
        l = [numpy.random.randint(0, self.maxn) for i in range(self.maxn)]
        self.axes.cla()
        self.axes.plot(range(self.maxn), l, 'r')
        self.draw()
        if self.b1_clicked:
                        self.b1_clicked = False
                        if self.maxn>2: self.maxn -= 1
        if self.b2_clicked:
                        self.b2_clicked = False
                        self.maxn += 1  
        

class ApplicationWindow(pyqtgraph.QtGui.QMainWindow):
    def __init__(self):
        pyqtgraph.QtGui.QMainWindow.__init__(self)
        self.setWindowTitle('matplotlib and pyqtpgraph integration example')
        
        self.main_widget = pyqtgraph.QtGui.QWidget(self)
        self.layout = pyqtgraph.QtGui.QVBoxLayout(self.main_widget)
        self.static_matplotlib_canvas = MyStaticMplCanvas(self.main_widget, 
width=5, height=4, dpi=100)
        self.dynamic_matplotlib_canvas = MyDynamicMplCanvas(self.main_widget, 
width=5, height=4, dpi=100)
             
        self.glw = pyqtgraph.LayoutWidget()
        self.b1_b = pyqtgraph.QtGui.QPushButton('-')
        self.b1_b.clicked.connect(self.b1_clicked)     
        self.b2_b = pyqtgraph.QtGui.QPushButton('+')
        self.b2_b.clicked.connect(self.b2_clicked)
        self.glw1 = self.glw.addWidget(self.b1_b, row=0, col=0)        
        self.glw1 = self.glw.addWidget(self.b2_b, row=0, col=1)        

        self.plw = pyqtgraph.PlotWidget()     
        self.p1 = self.plw.plot()        
        self.data1 = numpy.random.random(size = 300)        
        self.p1.setData(self.data1) 

        self.layout.addWidget(self.static_matplotlib_canvas)
        self.layout.addWidget(self.dynamic_matplotlib_canvas)        
        self.layout.addWidget(self.glw)
        self.layout.addWidget(self.plw)

        self.main_widget.setFocus()
        self.setCentralWidget(self.main_widget)
        
        self.timer = pyqtgraph.Qt.QtCore.QTimer()
        self.timer.timeout.connect(self.update)
        self.timer.start(100)   

    def update(self):
                self.data1[:-1] = self.data1[1:]                
                self.data1[-1] = numpy.random.normal()
                self.p1.setData(self.data1)

    def b1_clicked(self):
                self.dynamic_matplotlib_canvas.b1_clicked = True                
                
    def b2_clicked(self):
                self.dynamic_matplotlib_canvas.b2_clicked = True
        
qApp = pyqtgraph.QtGui.QApplication(sys.argv)
aw = ApplicationWindow()
aw.show()
sys.exit(qApp.exec_())

Reply via email to