From 78d74a71f46a122a32aa3b6c96d8aac8fa24381a Mon Sep 17 00:00:00 2001 From: Pavel 'LEdoian' Turinsky Date: Sat, 14 Jan 2023 06:24:35 +0100 Subject: [PATCH] Interactive pyplot window (poc 2018) --- poc2018.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/poc2018.py b/poc2018.py index 66bd401..785460d 100755 --- a/poc2018.py +++ b/poc2018.py @@ -25,6 +25,14 @@ class VisuFile: def __exit__(self, _et, _ev, _tb): plt.savefig(self.filename, format='pdf') +class VisuInter: + def __init__(self): + plt.ion() + def __enter__(self): + plt.clf() + def __exit__(self, _et, _ev, _tb): + plt.show(block=False) + def get_xml(): URL=r'https://www.volby.cz/pls/prez2018/vysledky' response = requests.get(URL) @@ -65,7 +73,7 @@ def fill_data(vysl) -> tuple[datetime, dict[str, int]]: return vysl.timestamp, vysl.kandidati def plot(ts, kand): - with VisuFile('/tmp/volby.pdf'): + with VisuInter(): order = ( 'Jiří Drahoš', 'Jiří Hynek', @@ -112,4 +120,9 @@ def visu_once(): ts, k = fill_data(v) plot(ts, k) -visu_once() +def loop(refresh=30): + while True: + visu_once() + plt.pause(refresh) + +loop()