Skip to content
New issue

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

Animations do not render #127

Open
HugoFara opened this issue Jul 14, 2023 · 7 comments
Open

Animations do not render #127

HugoFara opened this issue Jul 14, 2023 · 7 comments

Comments

@HugoFara
Copy link

Hello there!

As I just discovered this package, I have been following Fluids Tutorial to see whether I could have a nice animation. Unfortunately, copying exactly the provided code do not display anything.

I get one error warning after running vis.plot(trajectory, animate='time') (input [7] from the tutorial):

/python3.10/site-packages/matplotlib/animation.py:887: UserWarning: Animation was deleted without rendering anything. This is most likely not intended. To prevent deletion, assign the Animation to a variable, e.g. `anim`, that exists until you have outputted the Animation using `plt.show()` or `anim.save()`.

An easy fix I used was to remove plots.close(figure) on

plots.close(figure)

Doing so, the animation displays normally.

User Specifications

  • OS: Linux Mint 21
  • Python: 3.10
  • Matplotlib: 3.5.3, 3.6.3, 3.7.2 (same error)
  • PhiFlow: 2.4.0

Please tell me if you need more information!

@holl-
Copy link
Collaborator

holl- commented Jul 14, 2023

Hi,
Thanks for the bug report! Did you run the code within a Jupyter notebook or as a Python script?
The animation does work inside the Colab notebook.

@HugoFara
Copy link
Author

I'm running the example from a script, with the TkAgg backend.

As a side note, I cannot save the animation without my hack. I would get the following error: _tkinter.TclError: invalid command name ".!navigationtoolbar2tk.!button2".

@holl-
Copy link
Collaborator

holl- commented Jul 15, 2023

Interesting, I was always able to save the animations but I've pushed your change, bf136b1. Let's see if everything else still works...

@HugoFara
Copy link
Author

HugoFara commented Jul 15, 2023

Let's see if everything else still works...

Spoken like a true developer! 😆

I have been working with my hack without noticeable issue until now at least, so that seems fine.

More broadly, I often run into the issue of generating animations with matplotlib with my own projects, and I can say that closing the figures is rarely necessary.

More importantly, I used to use the same tricks to save the animation (see line 389)

LAST_FIGURE[0] = anim

The issue with this strategy is that it can result in a big memory leak as the animation is saved until a new animation is loaded. Usually I force the display of the animation and then return it, so this line may be unnecessary. It can become annoying, but I guess users are not supposed to use PhiFlow to run several minutes of animation.

@holl-
Copy link
Collaborator

holl- commented Jul 16, 2023

So it turns out that not closing the figure causes the animation to appear twice in Jupyter notebooks, even though no show() is called. Not returning it would be one possible fix but that is inconsistent. Do you know why it's showing up in the first place?

@HugoFara
Copy link
Author

I didn't check that, but I think one of the animation displaying is the output from the function, the other the figure we prepared that renders (matplotlib is always a bit annoying because of that).

Because returning the animation is nice, and that we want to close the figure, the easiest "fix" is to assign the output of the variable so that it is not displayed in Jupyter.

@holl-
Copy link
Collaborator

holl- commented Jul 17, 2023

Okay, for now I only close the plot when Jupyter is active. But maybe a better solution would be to to put a ; after the plot calls so the cell doesn't return the figure...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants