![]() ![]() Sitting for long periods of time is bad for your health, even on those days when you train and gain enough daily activity. Yet, more and more of us are spending a tremendous amount of time sitting each day at work, in traffic or watching TV, without much movement. In addition to being physically active, it's important to avoid prolonged sitting. It's widely known that physical activity is a major factor in maintaining health. Plt.pause(0.1) # pause 0.Simply put, our bodies are designed to move. Plt.axis() # set axis limits, to avoid rescaling Y = np.power(x, z/10) # y coordinates of plot for animation If there is an active figure, it will be updated and displayed before the pause.Īnd this is pretty much exactly what we want. The documentation of the plt.pause(interval) command states: Unfortunately those plots will not be interactive (they freeze), except you insert an input() command, but then the code will stop. Essentially plt.pause(0.001) seems to be the closest equivalent to matlab's drawnow. So here is a code that draws and updates a figure and keeps going. Plt.show() and plt.draw() are unnecessary and / or blocking in one way or the other. I figured out that the plt.pause(0.001) command is the only thing needed and nothing else. Here is a screenshot of VSCode alongside SumatraPDF, also the process is fast enough to get semi-live update rate (I can get near 10Hz on my setup just use time.sleep() between intervals) Sample code for outputing plot to a file import numpy as npĪfter first run, open the output file in one of the viewers mentioned above and enjoy. On Linux there are several options such as Evince (GNOME) and Ocular (KDE) On Windows I use SumatraPDF which is free, fast and light (only uses 1.8MB RAM for my case) PDF can support vector formats and there are lightweight viewers which support live updating.SVG is good but coudn't find good viewer for it except the web browser which by default needs manual refresh.Vector based formats are both small and fast This wasn't satisfactory for me so I found another solution outside of the box SaveToFile and View in external viewerįor this the saving and viewing should be both fast and the viewer shouldn't lock the file and should update the content automatically Selecting Format for Saving run the plot on a separate thread (too complicated). ![]() block the script from exiting (that's plt.show() and not what I want).If you think about it, after the script is finished, the program is terminated and there is no logical way to hold the plot this way, so there are two options This was my actual problem that couldn't find satisfactory answer for, I wanted plotting that didn't close after the script was finished (like MATLAB), If (cnt = 10): # update plot each 10 points If the amount of data is too much you can lower the update rate with a simple counter cnt += 1 # plt.axis(, x, -1, 1]) # disable autoscaling I forgot to say that I would like to update the existing window every time I plot something, instead of creating a new one. Plt.show(block=False) #this creates an empty frozen window. #plt.show() #this plots correctly, but blocks execution. from math import *įor pow in range(1,5): # plot x^1, x^2. Could you have a look at my code and tell me if you see something wrong? Here is my code. From other threads I've read, I suspect that whether show(block=False) works or not depends on the backend. If I simply call show(), the result is plotted properly but execution is blocked until the window is closed. I have tried using show(block=False) as some people suggest, but all I get is a frozen window. ![]() I am having problems trying to make matplotlib plot a function without blocking execution. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |