简体   繁体   中英

Matplotlib Figure flickering when updating

I have a plot in a PyQt window that updates every 10 seconds. The problem is that every time it updates the data in the figure there is a flicker which is quite annoying. Is there a way to solve this? See the code I use to draw the plot:

def _plot(self):
    self.fig.clear()
    chart1 = self.fig.add_subplot(2,1,1)
    chart2 = self.fig.add_subplot(2,1,2)
    chart1.grid(True)
    chart2.grid(True)
    chart1.plot(h_headers,reference)

    for row in rows:
        curve = []
        gap_curve = []
        for v in range(len(h_headers)-1):
            curve.append(#SOME NUMBERS#)
        chart1.plot(h_headers, curve)
        chart2.plot(h_headers, gap_curve)

    self.fig.patch.set_visible(False)
    self.canvas.draw()

To call the _plot method I use a Thread:

loop = True

class DataStream(threading.Thread):
    def __init__(self,queue):
        threading.Thread.__init__(self)
        self.queue = queue

    def run(self):
        while loop:
            window.update_numbers()
            window._plot()
            window.pyqttable.viewport().update()
            time.sleep(5)

Am I doing something wrong? Quite a noob here with Matplotlib, thanks!

In case anyone is having the same problem as me, I just changed

self.canvas.draw()

to

self.canvas.draw_idle()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM