'Plot signal data and skip frame with missing information using Matplotlib FuncAnimation

I am imitating getting stream of data where not each "message" line has the information I want to plot in live mode. Since each line will still be read, how can I skip one iteration (frame) and therefore skip plot update for 1 frame until next iteration that returns data comes along. My code has the following structure:

fig, ax = plt.subplots()
line, = ax.plot([], [])

lap_stat = []
file = open(path + 'file.log', 'r')

def update(lap_stat):

    #Plot lap number on x-axis, lap time on y-axis from lap_stat list that 
    #contains a tuple

    line.set_data(lap_stat[0], lap_stat[1])
    return line,
    
def data_gen():

    while True:
        line = file.readline()

        #Get data from line
        #Apply conditions, if line doesn't contain relevant information nothing happens
        #If data is present in line, save data as tuple [lap, lap_time] to lap_stat

        yield lap_stat

ani = FuncAnimation(fig, update, data_gen, interval=100, blit=True)
plt.show() 

Not each line has the relevant information, so if at current frame no information was appended the input list at update(lap_stat) function is empty, nothing gets plotted and the process dies. How can I modify my code to only plot information when it is returned? Plotting 0's also not an option, if I plot lap times from lap 0-10 and the then next data point is lap 15, I want the point from lap 10 to be connected to point 15. Hope it makes, thank you!



Sources

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

Source: Stack Overflow

Solution Source