Python Forum
[PyQt] Refresh x-labels in matplotlib animation widget
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyQt] Refresh x-labels in matplotlib animation widget
#3
Hi and sorry for my late response,

I thought thats its a general problem so I kept out the code. I chopped down the code to the essentials and will add it here.
The code is working so I dont post the imports and so on.

For testing purposes the live data is simulated by a .csv-file which is read in the initialisation. The test values are in range of 100 to 200. My problem is, that the labels of the x-ticks and the ticks itselfs are not refreshed according to the plotted data. The horizontal size of the graph is changing as further data is plotted, so in the background the setting of the x limits seems to work.

Any ideas? Thanks a lot

class Live_Window(FigureCanvas):
    
    def __init__(self, parent=None, width=5, height=4, dpi=100):
        
        super().__init__(mpl.figure.Figure())
        
        self.actRow = 10                  
        self.axis = self.figure.subplots()   
       
        self.axis.spines['bottom'].set_color('white')
        self.axis.spines['left'].set_color('white')
        self.axis.spines['right'].set_visible(False)
        self.axis.spines['top'].set_visible(False)
        self.axis.tick_params(axis='x', colors='white')
        self.axis.tick_params(axis='y', colors='white')
        self.axis.xaxis.label.set_color('white')
        self.axis.yaxis.label.set_color('white')
        self.axis.set_facecolor(('black'))
        self.figure.patch.set_facecolor('#2E3436')
        self.figure.tight_layout()
        

class MainWidget(QWidget, XYZ.Ui_Dialog):
    
    def __init__(self):
        
        super(MainWidget,self).__init__()  
        self.setupUi(self)
        self.init_Widget()
        self.counter = 1
        
        self.newData = pd.read_csv('Data.csv', sep=';')
        self.Time = self.newData.iloc[:,0]-self.newData.iloc[0,0]
        self.newData.iloc[:,0] = self.Time
              
        self.pb_StartMeasurement.clicked.connect(self.startMeasurement)
        
             
    def init_Widget(self):
        
        self.matplotlib_widget1 = Live_Window()
        self.layoutvertical1 = QVBoxLayout(self.plotWidget)
        self.layoutvertical1.addWidget(self.matplotlib_widget1)
        
        #create empty lists
        self.x = list(range(0,0))
        self.y = list(range(0,0))     
        self.line1, =  self.matplotlib_widget1.axis.plot(self.x, self.y, lw=1, color = 'chocolate')
        
    def update_line(self, i):
        
        ## append new data to data line
        self.y.append(self.newData.iloc[self.counter, self.matplotlib_widget1.actRow])
        self.x.append(self.newData.iloc[self.counter, 0])
        
        self.matplotlib_widget1.axis.set_xlim([0,max(self.x)])
        self.matplotlib_widget1.axis.set_ylim(min(self.y),max(self.y)+10)
             
        self.counter += 1
        self.line1.set_ydata(self.y)
        self.line1.set_xdata(self.x)     
              
        return [self.line1]
    
    ## triggered by pushbutton
    def startMeasurement(self):
       self.ani1 = FuncAnimation( self.matplotlib_widget1.figure, self.update_line, 
                                blit=True, interval=40)
 
    
if __name__ == '__main__':
    
    APP = QApplication(sys.argv)
    GUI = MainWidget()     
    GUI.show()
    APP.exec_()
    sys.exit(APP.exec())
Reply


Messages In This Thread
RE: Refresh x-labels in matplotlib animation widget - by JohnT - Apr-21-2021, 02:46 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] Tkinter Matplotlib Animation Graph not rendering dimidgen 3 607 Mar-12-2024, 02:09 PM
Last Post: deanhystad
  [Tkinter] cutomtkinter matplotlib no x,y - xaxis and x,y - labels-> only graph and grid visible dduric 0 326 Feb-20-2024, 07:09 PM
Last Post: dduric
  tkinter - update/refresh treeview snakes 5 20,984 Dec-02-2023, 07:05 PM
Last Post: aynous19
  Refresh image in label after every 1s using simple function jenkins43 1 5,502 Jul-28-2019, 02:49 PM
Last Post: Larz60+
  Unable to update or refresh label text in tkinter jenkins43 3 6,628 Jul-24-2019, 02:09 PM
Last Post: Friend
  Tkinter refresh eduardoforo 4 12,578 Nov-14-2018, 09:35 PM
Last Post: woooee
  [Tkinter] Label doesn't refresh jollydragon 7 6,997 Jul-13-2018, 05:55 AM
Last Post: jollydragon
  [PyQt] enviremont refresh duende 2 3,435 May-13-2018, 09:49 AM
Last Post: duende
  pyqt main window refresh poblems duende 0 5,383 Apr-13-2018, 05:05 PM
Last Post: duende
  Refresh test in urwid.Text Stensborg 1 4,547 Mar-05-2018, 11:23 AM
Last Post: Stensborg

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020