Python Forum

Full Version: How to show graph as a slideshow in PyQt5 using matplotlib
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am trying to implement a GUI app for graph plotting which should show graph as slideshow so that data can be visualized clearly for the users. Currently whole content of the file is read and plotted as a single figure,but I show to split the figure and show as slideshow ie first i want to plot first n set of data then next set likewise i wish to plot till the end of the file.
I have text file contains data as:
?
Quote:0.00 -10.742 10.7888 6.33455
1.00 -17.75391 10.0000 4.66778
4.00 -19.62891 15.9999 4.232323
20.00 -20.7641 18.6666 3.99999
23.00 -34.2300 2.7777 2.00000
50.00 -50.000 1.87878 2.77778
65.88 -22.5000 2.99999 1.45555
78.00 -30.000 1.55555 2.45667
86.00 -37.7900 2.55556 7.55679
90.00 -45.00000 13.6667 2.677888
----
----
200.02 200.01 0.0000 2.6667
300.00 300.02 1.6666 2.7878

What I have tried is:
from PyQt5.QtWidgets import *
    from PyQt5.uic import loadUi
    from matplotlib.backends.backend_qt5agg import (NavigationToolbar2QT as NavigationToolbar)
    import matplotlib.pyplot as plt
    import numpy as np
    from matplotlib import style
   
    import os
    class MatplotlibWidget(QMainWindow):
 
        def __init__(self):
            QMainWindow.__init__(self)
            loadUi("graphgenerate.ui", self)
            self.setWindowTitle("PyQt5 & Matplotlib Example GUI")
            self.playbutton.clicked.connect(self.drawGraph)
            self.addToolBar(NavigationToolbar(self.MplWidget.canvas, self))
         
 
        def drawGraph(self):
            f1 = open('TESTIP2.txt', 'r')
            print(f1)
            data = np.genfromtxt(f1)
            m = np.size(data, 0)
            n = np.size(data, 1)
            x = data[:, 0].reshape(m, 1)
            y = data[:, 1].reshape(m, 1)
            iters = m // 4
            xs=[]
            ys=[]
            for i in range(iters):
                xs.append(x[i])
                ys.append(y[i])
            self.MplWidget.canvas.axes.clear()
            self.MplWidget.canvas.axes.plot(xs,ys)
            self.MplWidget.canvas.axes.legend(('cosinus', 'sinus'), loc='upper right')
            self.MplWidget.canvas.axes.set_title('Signal' )
            self.MplWidget.canvas.draw()
 
    if __name__ == "__main__":
 
        app = QApplication([])
        window = MatplotlibWidget()
        window.show()
        app.exec_()
Please help to fix this. I will be thankful,if anyone help me out there.