简体   繁体   English

Matplotlib动画+ IPython:暂时禁用交互模式?

[英]Matplotlib animation + IPython: temporary disabling interactive mode?

I have a python a script that generates an animation using matplotlib's animation.FuncAnimation and animation.FFMpegWriter . 我有一个python脚本,该脚本使用matplotlib的animation.FuncAnimationanimation.FFMpegWriter生成animation.FFMpegWriter It works well, but there's an issue when running the code in IPython: each frame of the animation is displayed on screen while being generated, which slows down the movie generation process. 它运行良好,但是在IPython中运行代码时存在一个问题:动画的每一帧在生成时都会在屏幕上显示,这会减慢影片的生成过程。

I've tried issuing plt.ioff() before running the animation code, but the figure is still displayed on screen. 在运行动画代码之前,我曾尝试发出plt.ioff() ,但该图仍显示在屏幕上。 Is there a way to disable this behavior in IPython? 有没有一种方法可以在IPython中禁用此行为?

On a related note, if a run the script from a shell (ie python myMovieGenScript.py ), only one frame is shown, blocking execution. 与此相关的是,如果从外壳运行脚本(即python myMovieGenScript.py ),则仅显示一帧,从而阻止执行。 I can close it and the rest of the frames are rendered off screen (which is what I want). 我可以将其关闭,其余的帧将显示在屏幕外(这就是我想要的)。 Is there a way to prevent that single frame to be displayed, so no user interaction is required? 有没有一种方法可以防止显示单个框架,因此不需要用户交互?

正如@tcaswell指出的那样,问题是由间接调用plt.show()的回调引起的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM