'How to make xlim and ylim dynamically change?

I'm reading sensor data connected to Arduino, in the image below I want to make x_lim and y_lim change dynamically while reading data. for example, i need to add DateTime in x_lim and y_lim sensor values

enter image description here

class CustomFigCanvas(FigureCanvas, TimedAnimation):
    def __init__(self):
        self.addedData = []
        print(matplotlib.__version__)
        
        self.xlim = 200
        # The window
        self.fig = Figure(figsize=(5,5), dpi=100)
        self.ax1 = self.fig.add_subplot(111)
        # self.ax1 settings
        self.ax1.set_xlabel('time')
        self.ax1.set_ylabel('raw data')
        self.line1 = Line2D([], [], color='blue')
        self.line1_tail = Line2D([], [], color='red', linewidth=2)
        self.line1_head = Line2D([], [], color='red', marker='o', markeredgecolor='r')
        self.ax1.add_line(self.line1)
        self.ax1.add_line(self.line1_tail)
        self.ax1.add_line(self.line1_head)
        self.ax1.set_xlim(0, self.xlim - 1) # Here Should be sensor values change automatically 
        self.ax1.set_ylim(100, 400)         # Here Should be time in seconds change automatically 
        FigureCanvas.__init__(self, self.fig)
        TimedAnimation.__init__(self, self.fig, interval = 50, blit = True)
        return

def addData(self, value):
        self.addedData.append(value)
        return

def dataSendLoop(addData_callbackFunc):
    mySrc = Communicate()
    mySrc.data_signal.connect(addData_callbackFunc)

    n = np.linspace(0, 499, 500)
    y = []
    i = 0

    while(True):
        line = board.analogRead(0) # Here i reading sensor data
        y.append(line)
        mySrc.data_signal.emit(y[i]) # <- Here you emit a signal!
        i += 1


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source