Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

stop animation matplotlib

def onClick(event):
    global pause
    pause ^= True
fig.canvas.mpl_connect('button_press_event', onClick)
Comment

stop animation matplotlib

import matplotlib.pyplot as plt
import numpy as np
import matplotlib.animation as animation

pause = False
def simData():
    t_max = 10.0
    dt = 0.05
    x = 0.0
    t = 0.0
    while t < t_max:
        if not pause:
            x = np.sin(np.pi*t)
            t = t + dt
        yield x, t

def onClick(event):
    global pause
    pause ^= True

def simPoints(simData):
    x, t = simData[0], simData[1]
    time_text.set_text(time_template%(t))
    line.set_data(t, x)
    return line, time_text

fig = plt.figure()
ax = fig.add_subplot(111)
line, = ax.plot([], [], 'bo', ms=10)
ax.set_ylim(-1, 1)
ax.set_xlim(0, 10)

time_template = 'Time = %.1f s'
time_text = ax.text(0.05, 0.9, '', transform=ax.transAxes)
fig.canvas.mpl_connect('button_press_event', onClick)
ani = animation.FuncAnimation(fig, simPoints, simData, blit=False, interval=10,
    repeat=True)
fig.show()
Comment

PREVIOUS NEXT
Code Example
Python :: python hewwo world 
Python :: max sum slice python 1 - autopilot 
Python :: take input from clipboard python 
Python :: Handling single exception 
Python :: save multiple df to pkl 
Python :: Walrus operator in list comprehensions [Python 3.8.0] 
Python :: most efficient fibonacci number algorithm 
Python :: assertRaises property 
Python :: qaction disacble python 
Python :: how to loadh5 file in python 
Python :: import baseestimator 
Python :: convert from python to curl 
Python :: requests session 
Python :: python check for int 
Python :: finding anagrams in python 
Python :: unique items in a list python 
Python :: how to randomise a string in python 
Python :: python __dict__ 
Python :: python if statements 
Python :: linux python virtual environment 
Python :: remove list of value from list python 
Python :: add an index column in range dataframe 
Python :: rotate 2 dimensional list python 
Python :: list len python 
Python :: join tables pandas 
Python :: sequence in python 
Python :: hash password python 
Python :: rename data columns pandas 
Python :: how to find a key in a dictionary python 
Python :: how to check if user pressed enter in python 
ADD CONTENT
Topic
Content
Source link
Name
2+4 =