NeuroML / pyNeuroML

A single package in Python unifying scripts and modules for reading, writing, simulating and analysing NeuroML2/LEMS models.
https://docs.neuroml.org/Userdocs/Software/pyNeuroML.html
GNU Lesser General Public License v3.0
34 stars 30 forks source link

animate matplotlib plots #348

Closed YBCS closed 1 month ago

YBCS commented 2 months ago

279 wip fix

we can only use this feature if show_plot_already is set to True

YBCS commented 1 month ago

Can we also add saving of animations? Looks simple enough?

https://matplotlib.org/stable/users/explain/animations/animations.html#funcanimation

Saving animation is simple. But after some testing with the plots in the codebase I have identified some issues.

Animation is actually very expensive and so it takes lots of time. I have encountered plots with >= 10000 (link) In my machine saving animation plot with data length 1000 can take more almost a minute. Plot is a generic function, it is probably not a good idea if the plot will have lots of data.

On the other hand the script can choose not to save animation if the provided data point is too long. 1000 is a good threshold as it can save the animation within 1 minute.

sanjayankur31 commented 1 month ago

Can we also add saving of animations? Looks simple enough? https://matplotlib.org/stable/users/explain/animations/animations.html#funcanimation

Saving animation is simple. But after some testing with the plots in the codebase I have identified some issues.

Animation is actually very expensive and so it takes lots of time. I have encountered plots with >= 10000 (link) In my machine saving animation plot with data length 1000 can take more almost a minute. Plot is a generic function, it is probably not a good idea if the plot will have lots of data.

On the other hand the script can choose not to save animation if the provided data point is too long. 1000 is a good threshold as it can save the animation within 1 minute.

We can probably just document this in the method docstring and leave it for the user to decide. Often people in research labs have quite good computers, with lots of memory + good cores + gpus and all that. So, in such cases, they may be able to generate animations with more data points. So, it's best to include the functionality and document it. That way users can play around with a few parameters like "duration" and generate what works for them. What do you think?

sanjayankur31 commented 1 month ago

LGTM, merging. I'll make a few tweaks in my branch and merge to development :+1:

sanjayankur31 commented 1 month ago

@all-contributors please add @YBCS for code, test

allcontributors[bot] commented 1 month ago

@sanjayankur31

I've put up a pull request to add @YBCS! :tada: