Interactive pyplot window (poc 2018)

master
LEdoian 2 years ago
parent 6138b25d8c
commit 78d74a71f4

@ -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()

Loading…
Cancel
Save