Skip to content

BUG: Convert from str to writer on 3.2.x #17759

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

Merged
merged 2 commits into from
Jun 26, 2020
Merged

Conversation

larsoner
Copy link
Contributor

Just taking a simple animation example and trying to use anim.save(..., writer='imagemagick') when it's not available on the platform produces on v3.2.x (it's fine on master but is breaking some CIs currently that use 3.2):

Traceback (most recent call last):
  File "ani.py", line 45, in <module>
    ani.save('temp.gif', writer='imagemagick')
  File "/home/larsoner/python/matplotlib/lib/matplotlib/animation.py", line 1109, in save
    writer = alt_writer(
TypeError: 'str' object is not callable

On this PR:

MovieWriter imagemagick unavailable; trying to use pillow instead.

Code I used to test:

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from matplotlib.animation import ImageMagickWriter


def data_gen():
    for cnt in range(10):
        t = cnt / 10
        yield t, np.sin(2*np.pi*t) * np.exp(-t/10.)


def init():
    ax.set_ylim(-1.1, 1.1)
    ax.set_xlim(0, 10)
    del xdata[:]
    del ydata[:]
    line.set_data(xdata, ydata)
    return line,

fig, ax = plt.subplots()
line, = ax.plot([], [], lw=2)
ax.grid()
xdata, ydata = [], []


def run(data):
    # update the data
    t, y = data
    xdata.append(t)
    ydata.append(y)
    xmin, xmax = ax.get_xlim()

    if t >= xmax:
        ax.set_xlim(xmin, 2*xmax)
        ax.figure.canvas.draw()
    line.set_data(xdata, ydata)

    return line,


ImageMagickWriter.isAvailable = lambda: False  # emulate not available on the platform
ani = animation.FuncAnimation(fig, run, data_gen, blit=False, interval=10,
                              repeat=False, init_func=init)
ani.save('temp.gif', writer='imagemagick')

@@ -1106,6 +1106,8 @@ def func(current_frame: int, total_frames: int) -> Any
"save animations.")
_log.warning("MovieWriter %s unavailable; trying to use %s "
"instead.", writer, alt_writer)
if isinstance(alt_writer, str):
alt_writer = writers[alt_writer]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alt_writer is actually always a key in writers, so the if check could (should) be dropped.

@anntzer anntzer added topic: animation Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. labels Jun 25, 2020
@QuLogic
Copy link
Member

QuLogic commented Jun 25, 2020

I'm not sure this should target v3.2.x; I don't know if we have any plans for another bugfix release. @tacaswell

@larsoner
Copy link
Contributor Author

It's not a problem on master and the codepath on 3.3 looks very different, so feel free to close if you want

@tacaswell tacaswell merged commit 516c810 into matplotlib:v3.2.x Jun 26, 2020
@tacaswell
Copy link
Member

Even if we are not planning to do a 3.2.3, the work is done to fix this so we might as well merge it. If we need to do a 3.2.3 to address a show-stopping issue this fix will also go out.

@QuLogic QuLogic added this to the v3.2.3 milestone Jun 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. topic: animation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy