Repository navigation
Closed
Labels
Difficulty: Mediumhttps://matplotlib.org/devdocs/devel/contribute.html#good-first-issueshttps://matplotlib.org/devdocs/devel/contribute.html#good-first-issuestopic: animation🌱 Good first issueOpen a pull request against these issues if there are no active ones!Open a pull request against these issues if there are no active ones!
Milestone
Description
As pointed out in #17685 while you can pause an animation by reaching in and calling methods on the event source, when using Animation with blitting that is not enough, you also have to flip the animated artists back to non-animated. This code (lightly modified from @Luluser question) is a proof-of-concept.
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from matplotlib.widgets import Button
class PlotAnimation:
def __init__(self):
self.fig, self.ax = plt.subplots()
self.x = np.linspace(-10, 10, 1000)
self.N = 200
self.interv = 50
self.n0 = (
1.0
/ (4 * np.pi * 2e-4 * 0.1) ** 0.5
* np.exp(-self.x ** 2 / (4 * 2e-4 * 0.1))
)
(self.p,) = self.ax.plot(self.x, self.n0)
self.anim_running = True
self.Myanimation = animation.FuncAnimation(
self.fig, self.update, frames=self.N, interval=self.interv, blit=True
)
def update(self, i):
self.n0 += i / 100 % 5
self.p.set_ydata(self.n0 % 20)
return (self.p,)
def animate(self):
pause_ax = self.fig.add_axes((0.7, 0.025, 0.1, 0.04))
pause_button = Button(pause_ax, "pause", hovercolor="0.975")
pause_button.on_clicked(self._pause)
plt.show()
def _pause(self, event):
if self.anim_running:
self.Myanimation.event_source.stop()
self.p.set_animated(False)
self.anim_running = False
self.fig.canvas.draw_idle()
else:
self.p.set_animated(True)
self.Myanimation.event_source.start()
self.anim_running = True
animated_plot = PlotAnimation()
animated_plot.animate()This code should be generalized and used to put a pause and resume methods on Animation.
Metadata
Metadata
Assignees
Labels
Difficulty: Mediumhttps://matplotlib.org/devdocs/devel/contribute.html#good-first-issueshttps://matplotlib.org/devdocs/devel/contribute.html#good-first-issuestopic: animation🌱 Good first issueOpen a pull request against these issues if there are no active ones!Open a pull request against these issues if there are no active ones!
Activity
tacaswell commentedon Jun 19, 2020
For the tags:
DCtheTall commentedon Jun 22, 2020
Hey, I am interested in trying out working on a solution! I can probably get to it at some point in the coming week when I have some free time.
I have a few years of Python under my belt now and some experience with Python open source projects, so I think I can manage :)
tacaswell commentedon Jun 22, 2020
Great! We don't have a formal assignment process pre-PR but looking forward to seeing it!
deep529 commentedon Jun 23, 2020
Hi,
From the above pasted code, this is the solution I came up with.
This will be implemented in Animation Base Class.
Method to Pause
self.event_source.stop()figobject) usingMethod to Resume
figobject) usingself.event_source.start()I tried above solution and it worked as expected.
@tacaswell, Let me know if there is any mistake / improvement possible.
@DCtheTall, I am sorry, I could not found other issues suitable to my knowledge, and would like to continue working on it. (Hope you don't mind.)
DCtheTall commentedon Jun 24, 2020
@deep529 I am not an owner of this repository, I just volunteered for this issue. I don’t feel it’s my place to decide.
jklymak commentedon Jun 24, 2020
@deep529 Contributions are always welcome. However, if someone else has started working on something, its generally good form to ask before submitting a PR that solves the same problem. So in this case, lets give @DCtheTall a few days to open a PR. If he does, then perhaps you can help by reviewing. Of course, if he doesn't get to it in a few days, feel free to re-ping and we can reconsider. Thanks!
deep529 commentedon Jun 24, 2020
@jklymak, totally agree with your point.
But I jumped in because, he mentioned he will start working in the next week when he will get free time.
That's why I thought it is okay for me to try this out.
I did not want to hurt/discourage anyone. Really sorry if I did.
DCtheTall commentedon Jun 24, 2020
@deep529 thanks for being understanding!
I'm getting to it today. I had replied to the issue on a Sunday night and didn't want to overpromise, which is why I gave the flexible timeframe.
DCtheTall commentedon Jun 25, 2020
@tacaswell I built the repo on my Debian machine using the instructions here.
I installed matplotlib using
python3 -m pip3 install ., and am trying to run tests but getting the following error:Here is my
setup.cfg:Any idea on if I am missing anything? Lmk if you need more info.
EDIT:
It looks like ft2font wasn't built when I ran
python -m pip install .. Is there another command I need to build the C++ targets? Thanks in advance.DCtheTall commentedon Jun 28, 2020
@tacaswell friendly ping
jklymak commentedon Jun 28, 2020
You may want to look at #17096
DCtheTall commentedon Jul 2, 2020
@jklymak thanks! Followed the instructions in the PR and was able to run tests.
Fixing matplotlib#17689, added pause and resume methods for Animations
dopplershift commentedon Jul 29, 2020
Closed by #17826