I am trying to program an animated simulation using pylab and networkx. The simulation is not interesting all the time, so most of the time I want it to go fast, however I want it to be able to pause it and look at it when it looks interesting. Pausing the screen until pressing a key solves my problem, because I can press a key as quickly / slowly as I want.
Here is an example of a situation:
import numpy as np import networkx as nx import pylab as plt import sys def drawGraph(matrix): plt.clf() G = nx.DiGraph(np.array(matrix)) nx.draw_networkx(G) plt.draw() plt.pause(1)
How can I rewrite the line plt.pause (1) so that the program pauses until a key is pressed?
Some approaches suggested in other threads pause the program, but the image disappears or is not updated.
source share