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

Is there a way to stop the gif after one iteration? #5

Closed
sara-02 opened this issue Jul 10, 2020 · 4 comments
Closed

Is there a way to stop the gif after one iteration? #5

sara-02 opened this issue Jul 10, 2020 · 4 comments

Comments

@sara-02
Copy link

sara-02 commented Jul 10, 2020

I want to show a bar plot where bar for the next unit on x-axis appear one after the other and then stop once the last point is reached.
I managed to successfully create my bar plot and save the the gif, however the gif loops which I do not want.
Is there a way to repeat loops?

@maxhumber
Copy link
Owner

Hey @sara-02!

You're the second person to ask for this functionality! 🙈 (#3)

If there I get 3 more people asking for it, I'll formalize it into a feature 🤓

For now you can work around with:

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])
    if x[i] > 50 and x[i] < 70:
        plt.axvspan(50, x[i-1], facecolor="Red", ls="--", lw=2.0, alpha=0.2)
    if x[i] >= 70:
        plt.axvspan(50, 70, facecolor="Red", ls="--", lw=2.0, alpha=0.2)

frames = []
for i in range(len(x)):
    frame = plot(i)
    frames.append(frame)

# IMPORTANT SAVE CODE HERE:
frames[0].save(
    "dont_repeat.gif",
    save_all=True,
    append_images=frames[1:],
    duration=70
)

Which will produce (for some reason macOS Preview doesn't support non-looping gifs? But the web does?):

dont_repeat

Hope that helps!

@sara-02
Copy link
Author

sara-02 commented Jul 12, 2020

hey @maxhumber I tried a similar approach as you mentioned, still not able to stop the loop :/.
Can I share the gist code with you to have a look at?

@maxhumber
Copy link
Owner

Sure! I'll take a look :)

@robertryanharrison
Copy link

humble vote for the feature; noob here thanks for creating this package!

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

3 participants