-
-
Notifications
You must be signed in to change notification settings - Fork 48
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
Issues with decorated function arguments used for conditionals, and non-looping gifs #3
Comments
Hey @davidwych! Thanks for the issue and suggestion. I can look at adding the non-loop parameter 👍 Can I ask why you want it? I've never had a scenario when I didn't want something to loop. As for the other issue. Could you drop in your data, so I can poke at it? |
(1) The non-loop functionality would be useful for "one-time use" animations (e.g. in my case I'm creating this gif for a slide in a presentation, so I really just need the animation to run through once and then stay in the form it's in at the last frame for the remaining time I'm presenting the slide). (2) Here's the piano data: to load it:
n.b. in the code above: replace |
Okay, figured out your first thing! Seems like you need to adjust your See this reproducible example: import gif
from matplotlib import pyplot as plt
x = list(range(100))
y = [10] * len(x)
@gif.frame
def plot(i):
plt.plot(x[:i], y[:i])
plt.xlim([0, max(x)])
plt.ylim([0, max(y) * 2])
# track the RED note
if x[i] > 50 and x[i] < 70:
plt.axvspan(50, x[i-1], facecolor="Red", ls="--", lw=2.0, alpha=0.2)
# track the BLUE note
if x[i] > 80 and x[i] < 90:
plt.axvspan(80, x[i-1], facecolor="Blue", ls="--", lw=2.0, alpha=0.2)
# make sure the RED stays on
if x[i] >= 70:
plt.axvspan(50, 70, facecolor="Red", ls="--", lw=2.0, alpha=0.2)
# make sure the BLUE stays on
if x[i] >= 90:
plt.axvspan(80, 90, facecolor="Blue", ls="--", lw=2.0, alpha=0.2)
frames = []
for i in range(len(x)):
frame = plot(i)
frames.append(frame)
gif.save(frames, 'piano.gif', duration=30) Output: |
As for the non-looping. Let me meditate on it... for now... just skip the slide a millisecond before it finishes 🤣 |
Thanks so much! Sorry if this wasn't really an "issue" so much as me not knowing how conditionals work... :| I thought maybe it had something to do with how arguments are handled by the decorator. |
In trying to plot an audio signal stored in the array
piano
as a function of timet
, in increments of 1000 elements, with various parts of the signal highlighted as the animation goes on withaxvspan
, I created the function:with the gif creation loop:
Problem is, none of the conditionals ever get triggered. All I get is the audio signal, no
vspans
or inclusion of the legend elements:Also, is there any way to have the gif not loop? I know in
gif.py
the setting haveloop=0
what do we set that to to get it to not loop? Can this be added as an argument togif.save()
?The text was updated successfully, but these errors were encountered: