| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| """ | ||
| ===== | ||
| Decay | ||
| ===== | ||
|
|
||
| This example showcases: | ||
| - using PlayerAnimation | ||
| - using blitting | ||
| - changing axes limits during an animation. | ||
| """ | ||
|
|
||
| import itertools | ||
|
|
||
| import numpy as np | ||
| import matplotlib.pyplot as plt | ||
|
|
||
| from matplotlib.animation import PlayerAnimation, FuncAnimation | ||
| import math | ||
|
|
||
| def data_gen(): | ||
| for cnt in itertools.count(): | ||
| yield cnt | ||
|
|
||
| def init(val): | ||
| global line | ||
| print(f"init with val: {val}") | ||
| if not "line" in globals(): | ||
| line, = ax.plot([], [], lw=2) | ||
| ax.grid() | ||
| ax.set_ylim(-1.1, 1.1) | ||
| ax.set_xlim(0, 1 + math.floor(val / 10)) | ||
| line.set_data([], []) | ||
| return [line] | ||
|
|
||
| fig, ax = plt.subplots() | ||
|
|
||
| def update_plot(i): | ||
| # update the data | ||
| xdata = np.linspace(-10, 10, 1000) | ||
| ydata = np.sin(xdata + i*0.1) | ||
| _, xmax = ax.get_xlim() | ||
| new_xmax = 1 + math.floor(i / 10) | ||
| if xmax != new_xmax: | ||
| ax.set_xlim(0, new_xmax) | ||
| ax.figure.canvas.draw_idle() | ||
| line.set_data(xdata, ydata) | ||
|
|
||
| return [line] | ||
|
|
||
| animation = PlayerAnimation(fig=fig, func=update_plot, init_func=init, interval=100, blit=True, valstep=0.5) | ||
| plt.show() |
| Back | FazBrowse Home | New Git URL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityThis is going to need a docstring including the required signatures of the functions passed in.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.