Interactive pyplot window

master
LEdoian 2 years ago
parent 847014949d
commit 6138b25d8c

@ -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/prez2023/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 = (
'Petr Pavel',
'Danuše Nerudová',
@ -110,4 +118,9 @@ def visu_once():
ts, k = fill_data(v)
plot(ts, k)
def loop(refresh=30):
while True:
visu_once()
plt.pause(refresh)
loop()

Loading…
Cancel
Save