I had a look at the code again and found out, how to make it work. What made it work was putting the plt.pause
in front of the code block below.
This does solve my problem, but I am not sure why.
plt.pause(1 / frequenz)
# Check if maximum length is reached
if (all(len(data) >= zeitdauer * frequenz for data in
temperature_data.values()) or not plt.fignum_exists(fig.number)):
print("Program stopped")
client.close()
return