Animation in iPython notebookOnline matplotlib animation in Jupyter notebookAnimation can only display the firstframeMatplotlib animate - empty axisFuncAnimation displays only one frameInline animations in JupyterHow do you update inline images in Ipython?How can i dynamically (in a loop) show images in google colab?Dynamic plot in python jupyter notebook using drawnowhow to run plt.draw/plt.pause function on jupyter-notebook to update plotsSimple Python/Matplotlib animation shows: empty graph - why?How do I animate constraint changes?How to write LaTeX in IPython Notebook?Using IPython notebooks under version controlHow to make IPython notebook matplotlib plot inlineIPython Notebooks UnreadableIPython notebook error opening after trying to pip install pycloud on Anacondaport usage in the ipython notebookmatplotlib in ipython notebook: need functionality like manipulate function in Mathematicaautoupdate module in IPython / jupyter notebookipython notebook not opening on windows 7
Complaints from (junior) developers against solution architects: how can we show the benefits of our work and improve relationships?
Why doesn't the Gottesman-Knill theorem render quantum computing almost useless?
Why put copper in between battery contacts and clamps?
How to find the three closest (nearest) values within a vector?
Why don't short runways use ramps for takeoff?
Solve equation using Mathematica
What is my clock telling me to do?
Is there a word to describe someone who is, or the state of being, content with hanging around others without interacting with them?
On what tickets or flights are Flying Blue XP earned?
Applications of pure mathematics in operations research
How would a lunar colony attack Earth?
What is a good example for artistic ND filter applications?
Microgravity indicators
Would people understand me speaking German all over Europe?
Was the Psych theme song written for the show?
What force enables us to walk? Friction or normal reaction?
How do I say "this is why…"?
Load Product Qty by sku in Magento 2 Controller
How did astronauts using rovers tell direction without compasses on the Moon?
Can a US President, after impeachment and removal, be re-elected or re-appointed?
Tektro Spyre C - is the rotor riveted to the hub?
What is a Trio Word™?
Correct word for a little toy that always stands up?
Is it okay for me to decline a project on ethical grounds?
Animation in iPython notebook
Online matplotlib animation in Jupyter notebookAnimation can only display the firstframeMatplotlib animate - empty axisFuncAnimation displays only one frameInline animations in JupyterHow do you update inline images in Ipython?How can i dynamically (in a loop) show images in google colab?Dynamic plot in python jupyter notebook using drawnowhow to run plt.draw/plt.pause function on jupyter-notebook to update plotsSimple Python/Matplotlib animation shows: empty graph - why?How do I animate constraint changes?How to write LaTeX in IPython Notebook?Using IPython notebooks under version controlHow to make IPython notebook matplotlib plot inlineIPython Notebooks UnreadableIPython notebook error opening after trying to pip install pycloud on Anacondaport usage in the ipython notebookmatplotlib in ipython notebook: need functionality like manipulate function in Mathematicaautoupdate module in IPython / jupyter notebookipython notebook not opening on windows 7
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I am trying to put animations in an iPython notebook and am not finding a solution. I saw one post that discussed using interactive widgets, but there are a couple problems that I have with this: First, every example I see with widgets uses a slider or some other input, whereas I just want the animation to run automatically when the cell is run. Second, all the documentation seems out of date on Jupyter's site--whenever I download and run their notebooks I get these messages about certain modules being deprecated and then later in the file something fails to run, presumably because they're trying to import and access files that no longer exist.
I've seen a few other pages on the topic but they often require downloading binaries or other modules, but I'm partly using this to teach some students Math and I've gotten them to download Anaconda--I was hoping to not further confuse the issue by making them also download and install more complicated things all while spending time not talking about the Math.
So in short, is there a way that I can create animations in an iPython notebook that only require the use of simple import commands that will run out-of-the-box so to speak with the software that comes from Anaconda?
[Edit: I should also note that I've used Tkinter to make animations, and I could make one in matplotlib I'm sure. So if there were a way to get the animations you produce with those to render in an iPython notebook, that would certainly be a working solution for me.]
[Further edit: I suppose I could also say what I am hoping to animate at the moment, although I really want to be pretty flexible about the range of things I could animate if I decide to. Right now I'm trying to make a digital clock that displays each digit in Sumerian base-60 numerals to illustrate a different counting and base system. So it should initially display | then after a second || and so on until ten gets represented as < and so on until eventually the clock ticks over to a minute where it now displays |:| to represent one minute, one second.]
python-3.x animation ipython jupyter-notebook
add a comment |
I am trying to put animations in an iPython notebook and am not finding a solution. I saw one post that discussed using interactive widgets, but there are a couple problems that I have with this: First, every example I see with widgets uses a slider or some other input, whereas I just want the animation to run automatically when the cell is run. Second, all the documentation seems out of date on Jupyter's site--whenever I download and run their notebooks I get these messages about certain modules being deprecated and then later in the file something fails to run, presumably because they're trying to import and access files that no longer exist.
I've seen a few other pages on the topic but they often require downloading binaries or other modules, but I'm partly using this to teach some students Math and I've gotten them to download Anaconda--I was hoping to not further confuse the issue by making them also download and install more complicated things all while spending time not talking about the Math.
So in short, is there a way that I can create animations in an iPython notebook that only require the use of simple import commands that will run out-of-the-box so to speak with the software that comes from Anaconda?
[Edit: I should also note that I've used Tkinter to make animations, and I could make one in matplotlib I'm sure. So if there were a way to get the animations you produce with those to render in an iPython notebook, that would certainly be a working solution for me.]
[Further edit: I suppose I could also say what I am hoping to animate at the moment, although I really want to be pretty flexible about the range of things I could animate if I decide to. Right now I'm trying to make a digital clock that displays each digit in Sumerian base-60 numerals to illustrate a different counting and base system. So it should initially display | then after a second || and so on until ten gets represented as < and so on until eventually the clock ticks over to a minute where it now displays |:| to represent one minute, one second.]
python-3.x animation ipython jupyter-notebook
There is JSAnimation, but it requires extra installation. You can replace an output such as a plot with IPython.display.clear_output, but it won't be smooth enough to properly animate something.
– Thomas K
May 23 '16 at 10:32
JSAnimation does not require extra installation anymore. It has been merged into matplotlib since version 2.1. Usage is shown in the last snippet in answer by @ImportanceOfBeingErnest.
– Harsh
Nov 11 '17 at 23:54
add a comment |
I am trying to put animations in an iPython notebook and am not finding a solution. I saw one post that discussed using interactive widgets, but there are a couple problems that I have with this: First, every example I see with widgets uses a slider or some other input, whereas I just want the animation to run automatically when the cell is run. Second, all the documentation seems out of date on Jupyter's site--whenever I download and run their notebooks I get these messages about certain modules being deprecated and then later in the file something fails to run, presumably because they're trying to import and access files that no longer exist.
I've seen a few other pages on the topic but they often require downloading binaries or other modules, but I'm partly using this to teach some students Math and I've gotten them to download Anaconda--I was hoping to not further confuse the issue by making them also download and install more complicated things all while spending time not talking about the Math.
So in short, is there a way that I can create animations in an iPython notebook that only require the use of simple import commands that will run out-of-the-box so to speak with the software that comes from Anaconda?
[Edit: I should also note that I've used Tkinter to make animations, and I could make one in matplotlib I'm sure. So if there were a way to get the animations you produce with those to render in an iPython notebook, that would certainly be a working solution for me.]
[Further edit: I suppose I could also say what I am hoping to animate at the moment, although I really want to be pretty flexible about the range of things I could animate if I decide to. Right now I'm trying to make a digital clock that displays each digit in Sumerian base-60 numerals to illustrate a different counting and base system. So it should initially display | then after a second || and so on until ten gets represented as < and so on until eventually the clock ticks over to a minute where it now displays |:| to represent one minute, one second.]
python-3.x animation ipython jupyter-notebook
I am trying to put animations in an iPython notebook and am not finding a solution. I saw one post that discussed using interactive widgets, but there are a couple problems that I have with this: First, every example I see with widgets uses a slider or some other input, whereas I just want the animation to run automatically when the cell is run. Second, all the documentation seems out of date on Jupyter's site--whenever I download and run their notebooks I get these messages about certain modules being deprecated and then later in the file something fails to run, presumably because they're trying to import and access files that no longer exist.
I've seen a few other pages on the topic but they often require downloading binaries or other modules, but I'm partly using this to teach some students Math and I've gotten them to download Anaconda--I was hoping to not further confuse the issue by making them also download and install more complicated things all while spending time not talking about the Math.
So in short, is there a way that I can create animations in an iPython notebook that only require the use of simple import commands that will run out-of-the-box so to speak with the software that comes from Anaconda?
[Edit: I should also note that I've used Tkinter to make animations, and I could make one in matplotlib I'm sure. So if there were a way to get the animations you produce with those to render in an iPython notebook, that would certainly be a working solution for me.]
[Further edit: I suppose I could also say what I am hoping to animate at the moment, although I really want to be pretty flexible about the range of things I could animate if I decide to. Right now I'm trying to make a digital clock that displays each digit in Sumerian base-60 numerals to illustrate a different counting and base system. So it should initially display | then after a second || and so on until ten gets represented as < and so on until eventually the clock ticks over to a minute where it now displays |:| to represent one minute, one second.]
python-3.x animation ipython jupyter-notebook
python-3.x animation ipython jupyter-notebook
edited May 23 '16 at 10:30
Thomas K
31.5k5 gold badges67 silver badges76 bronze badges
31.5k5 gold badges67 silver badges76 bronze badges
asked Feb 21 '16 at 4:58
AddemAddem
1,4181 gold badge11 silver badges34 bronze badges
1,4181 gold badge11 silver badges34 bronze badges
There is JSAnimation, but it requires extra installation. You can replace an output such as a plot with IPython.display.clear_output, but it won't be smooth enough to properly animate something.
– Thomas K
May 23 '16 at 10:32
JSAnimation does not require extra installation anymore. It has been merged into matplotlib since version 2.1. Usage is shown in the last snippet in answer by @ImportanceOfBeingErnest.
– Harsh
Nov 11 '17 at 23:54
add a comment |
There is JSAnimation, but it requires extra installation. You can replace an output such as a plot with IPython.display.clear_output, but it won't be smooth enough to properly animate something.
– Thomas K
May 23 '16 at 10:32
JSAnimation does not require extra installation anymore. It has been merged into matplotlib since version 2.1. Usage is shown in the last snippet in answer by @ImportanceOfBeingErnest.
– Harsh
Nov 11 '17 at 23:54
There is JSAnimation, but it requires extra installation. You can replace an output such as a plot with IPython.display.clear_output, but it won't be smooth enough to properly animate something.
– Thomas K
May 23 '16 at 10:32
There is JSAnimation, but it requires extra installation. You can replace an output such as a plot with IPython.display.clear_output, but it won't be smooth enough to properly animate something.
– Thomas K
May 23 '16 at 10:32
JSAnimation does not require extra installation anymore. It has been merged into matplotlib since version 2.1. Usage is shown in the last snippet in answer by @ImportanceOfBeingErnest.
– Harsh
Nov 11 '17 at 23:54
JSAnimation does not require extra installation anymore. It has been merged into matplotlib since version 2.1. Usage is shown in the last snippet in answer by @ImportanceOfBeingErnest.
– Harsh
Nov 11 '17 at 23:54
add a comment |
4 Answers
4
active
oldest
votes
Some options you have for animating plots in Jupyter/IPython, using matplotlib:
Using
displayin a loop UseIPython.display.display(fig)to display a figure in the output. Using a loop you would want to clear the output before a new figure is shown. Note that this technique gives in general not so smooth resluts. I would hence advice to use any of the below.import matplotlib.pyplot as plt
import matplotlib.animation
import numpy as np
from IPython.display import display, clear_output
t = np.linspace(0,2*np.pi)
x = np.sin(t)
fig, ax = plt.subplots()
l, = ax.plot([0,2*np.pi],[-1,1])
animate = lambda i: l.set_data(t[:i], x[:i])
for i in range(len(x)):
animate(i)
clear_output(wait=True)
display(fig)
plt.show()%matplotlib notebookUse IPython magic%matplotlib notebookto set the backend to the notebook backend. This will keep the figure alive instead of displaying a static png file and can hence also show animations.
Complete example:%matplotlib notebook
import matplotlib.pyplot as plt
import matplotlib.animation
import numpy as np
t = np.linspace(0,2*np.pi)
x = np.sin(t)
fig, ax = plt.subplots()
l, = ax.plot([0,2*np.pi],[-1,1])
animate = lambda i: l.set_data(t[:i], x[:i])
ani = matplotlib.animation.FuncAnimation(fig, animate, frames=len(t))
plt.show()%matplotlib tkUse IPython magic%matplotlib tkto set the backend to the tk backend. This will open the figure in a new plotting window, which is interactive and can thus also show animations.
Complete example:%matplotlib tk
import matplotlib.pyplot as plt
import matplotlib.animation
import numpy as np
t = np.linspace(0,2*np.pi)
x = np.sin(t)
fig, ax = plt.subplots()
l, = ax.plot([0,2*np.pi],[-1,1])
animate = lambda i: l.set_data(t[:i], x[:i])
ani = matplotlib.animation.FuncAnimation(fig, animate, frames=len(t))
plt.show()Convert animation to mp4 video (option mentionned by @Perfi already):
from IPython.display import HTML
HTML(ani.to_html5_video())or use
plt.rcParams["animation.html"] = "html5"at the beginning of the notebook.
This will require to have ffmpeg video codecs available to convert to HTML5 video. The video is then shown inline. This is therefore compatible with%matplotlib inlinebackend. Complete example:%matplotlib inline
import matplotlib.pyplot as plt
plt.rcParams["animation.html"] = "html5"
import matplotlib.animation
import numpy as np
t = np.linspace(0,2*np.pi)
x = np.sin(t)
fig, ax = plt.subplots()
l, = ax.plot([0,2*np.pi],[-1,1])
animate = lambda i: l.set_data(t[:i], x[:i])
ani = matplotlib.animation.FuncAnimation(fig, animate, frames=len(t))
ani%matplotlib inline
import matplotlib.pyplot as plt
import matplotlib.animation
import numpy as np
t = np.linspace(0,2*np.pi)
x = np.sin(t)
fig, ax = plt.subplots()
l, = ax.plot([0,2*np.pi],[-1,1])
animate = lambda i: l.set_data(t[:i], x[:i])
ani = matplotlib.animation.FuncAnimation(fig, animate, frames=len(t))
from IPython.display import HTML
HTML(ani.to_html5_video())Convert animation to JavaScript:
from IPython.display import HTML
HTML(ani.to_jshtml())or use
plt.rcParams["animation.html"] = "jshtml"at the beginning of the notebook.
This will display the animation as HTML with JavaScript. This highly compatible with most new browsers and also with the%matplotlib inlinebackend. It is available in matplotlib 2.1 or higher.
Complete example:%matplotlib inline
import matplotlib.pyplot as plt
plt.rcParams["animation.html"] = "jshtml"
import matplotlib.animation
import numpy as np
t = np.linspace(0,2*np.pi)
x = np.sin(t)
fig, ax = plt.subplots()
l, = ax.plot([0,2*np.pi],[-1,1])
animate = lambda i: l.set_data(t[:i], x[:i])
ani = matplotlib.animation.FuncAnimation(fig, animate, frames=len(t))
ani%matplotlib inline
import matplotlib.pyplot as plt
import matplotlib.animation
import numpy as np
t = np.linspace(0,2*np.pi)
x = np.sin(t)
fig, ax = plt.subplots()
l, = ax.plot([0,2*np.pi],[-1,1])
animate = lambda i: l.set_data(t[:i], x[:i])
ani = matplotlib.animation.FuncAnimation(fig, animate, frames=len(t))
from IPython.display import HTML
HTML(ani.to_jshtml())
Quick question, since I don't understand these backend things at all, how would you recommend learning about them? Is there a book, or some general topic that I can look up, in order to study whatever is necessary to understand them? Or perhaps a better question: In what class would you learn about these, if you were taking a CompSci course?
– Addem
Oct 23 '17 at 22:58
I have no idea about CompSci courses. I guess you learn about them by using them. There is a matplotlib page about them. Concerning Jupyter, there is this page as introduction.
– ImportanceOfBeingErnest
Oct 24 '17 at 6:33
Converting animation to JavaScript in matplotlib is a boon, especially as it removes the hassle of installing ffmpeg codecs for someone in a hurry. @ImportanceOfBeingErnest Nice use of code snippets in the answer. Can I know if putting the code as CSS in the answer was a deliberate choice or is it the same for HTML/JS etc? I must confess I spent a few confused minutes just clicking theRun code snippetexpecting to see some python output.
– Harsh
Nov 12 '17 at 0:13
@Harsh Sorry for the confusion. I misused this css/javascrip feature to hide the code in order not to clutter the answer. This allows to clearly see all options in the answer, but at the same time gives a complete example for anyone in need of it (I always like to provide mcves to make some command unambiguous.) Unfortunately this "Hide Code" feature is not available for other languages like python.
– ImportanceOfBeingErnest
Nov 12 '17 at 9:02
The first (slow) method above is very useful for on-line animations, i.e., for when you are generating data frame by frame, rather than having it all a priori.
– Novak
Jan 16 '18 at 2:45
add a comment |
You may find this tutorial interesting.
If you can turn what you need into a matplotlib animation, and I'm fairly sure from your description that it's possible, you can then use
from matplotlib import rc, animation
rc('animation', html='html5')
and display your animation using
anim = animation.FuncAnimation(fig, animate, init_func=init,
frames=N, interval=20, blit=True)
anim
Might come in handy!
add a comment |
I had a similar problem, and this question helped me get started. I put together a notebook that illustrates using FuncAnimation along with good explanations of why the notebook does some things the way it does. It also has links to instructions on FFmpeg. It also has links to the examples I used in developing and understanding of animations. You can view my contribution at:
Animation Illustration
For your question, you might find interactive sliders a better tool. I also created a notebook which demonstrates interactive widgets in Jupyter. It is available here; however, the interactive parts don't work there.
Both are available in a GitHub Repostory
add a comment |
Jupyter widgets is a good way of displaying animations. The code below displays an animated gif.....
from ipywidgets import Image
from IPython import display
animatedGif = "animatedGifs/01-progress.gif" #path relative to your notebook
file = open(animatedGif , "rb")
image = file.read()
progress= Image(
value=image,
format='gif',
width=100,
height=100)
display.display(progress)
You can close this animation using:
progress.close()
N.B. I found a few nice animated gifs from http://www.downgraf.com/inspiration/25-beautiful-loading-bar-design-examples-gif-animated/.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f35532498%2fanimation-in-ipython-notebook%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
Some options you have for animating plots in Jupyter/IPython, using matplotlib:
Using
displayin a loop UseIPython.display.display(fig)to display a figure in the output. Using a loop you would want to clear the output before a new figure is shown. Note that this technique gives in general not so smooth resluts. I would hence advice to use any of the below.import matplotlib.pyplot as plt
import matplotlib.animation
import numpy as np
from IPython.display import display, clear_output
t = np.linspace(0,2*np.pi)
x = np.sin(t)
fig, ax = plt.subplots()
l, = ax.plot([0,2*np.pi],[-1,1])
animate = lambda i: l.set_data(t[:i], x[:i])
for i in range(len(x)):
animate(i)
clear_output(wait=True)
display(fig)
plt.show()%matplotlib notebookUse IPython magic%matplotlib notebookto set the backend to the notebook backend. This will keep the figure alive instead of displaying a static png file and can hence also show animations.
Complete example:%matplotlib notebook
import matplotlib.pyplot as plt
import matplotlib.animation
import numpy as np
t = np.linspace(0,2*np.pi)
x = np.sin(t)
fig, ax = plt.subplots()
l, = ax.plot([0,2*np.pi],[-1,1])
animate = lambda i: l.set_data(t[:i], x[:i])
ani = matplotlib.animation.FuncAnimation(fig, animate, frames=len(t))
plt.show()%matplotlib tkUse IPython magic%matplotlib tkto set the backend to the tk backend. This will open the figure in a new plotting window, which is interactive and can thus also show animations.
Complete example:%matplotlib tk
import matplotlib.pyplot as plt
import matplotlib.animation
import numpy as np
t = np.linspace(0,2*np.pi)
x = np.sin(t)
fig, ax = plt.subplots()
l, = ax.plot([0,2*np.pi],[-1,1])
animate = lambda i: l.set_data(t[:i], x[:i])
ani = matplotlib.animation.FuncAnimation(fig, animate, frames=len(t))
plt.show()Convert animation to mp4 video (option mentionned by @Perfi already):
from IPython.display import HTML
HTML(ani.to_html5_video())or use
plt.rcParams["animation.html"] = "html5"at the beginning of the notebook.
This will require to have ffmpeg video codecs available to convert to HTML5 video. The video is then shown inline. This is therefore compatible with%matplotlib inlinebackend. Complete example:%matplotlib inline
import matplotlib.pyplot as plt
plt.rcParams["animation.html"] = "html5"
import matplotlib.animation
import numpy as np
t = np.linspace(0,2*np.pi)
x = np.sin(t)
fig, ax = plt.subplots()
l, = ax.plot([0,2*np.pi],[-1,1])
animate = lambda i: l.set_data(t[:i], x[:i])
ani = matplotlib.animation.FuncAnimation(fig, animate, frames=len(t))
ani%matplotlib inline
import matplotlib.pyplot as plt
import matplotlib.animation
import numpy as np
t = np.linspace(0,2*np.pi)
x = np.sin(t)
fig, ax = plt.subplots()
l, = ax.plot([0,2*np.pi],[-1,1])
animate = lambda i: l.set_data(t[:i], x[:i])
ani = matplotlib.animation.FuncAnimation(fig, animate, frames=len(t))
from IPython.display import HTML
HTML(ani.to_html5_video())Convert animation to JavaScript:
from IPython.display import HTML
HTML(ani.to_jshtml())or use
plt.rcParams["animation.html"] = "jshtml"at the beginning of the notebook.
This will display the animation as HTML with JavaScript. This highly compatible with most new browsers and also with the%matplotlib inlinebackend. It is available in matplotlib 2.1 or higher.
Complete example:%matplotlib inline
import matplotlib.pyplot as plt
plt.rcParams["animation.html"] = "jshtml"
import matplotlib.animation
import numpy as np
t = np.linspace(0,2*np.pi)
x = np.sin(t)
fig, ax = plt.subplots()
l, = ax.plot([0,2*np.pi],[-1,1])
animate = lambda i: l.set_data(t[:i], x[:i])
ani = matplotlib.animation.FuncAnimation(fig, animate, frames=len(t))
ani%matplotlib inline
import matplotlib.pyplot as plt
import matplotlib.animation
import numpy as np
t = np.linspace(0,2*np.pi)
x = np.sin(t)
fig, ax = plt.subplots()
l, = ax.plot([0,2*np.pi],[-1,1])
animate = lambda i: l.set_data(t[:i], x[:i])
ani = matplotlib.animation.FuncAnimation(fig, animate, frames=len(t))
from IPython.display import HTML
HTML(ani.to_jshtml())
Quick question, since I don't understand these backend things at all, how would you recommend learning about them? Is there a book, or some general topic that I can look up, in order to study whatever is necessary to understand them? Or perhaps a better question: In what class would you learn about these, if you were taking a CompSci course?
– Addem
Oct 23 '17 at 22:58
I have no idea about CompSci courses. I guess you learn about them by using them. There is a matplotlib page about them. Concerning Jupyter, there is this page as introduction.
– ImportanceOfBeingErnest
Oct 24 '17 at 6:33
Converting animation to JavaScript in matplotlib is a boon, especially as it removes the hassle of installing ffmpeg codecs for someone in a hurry. @ImportanceOfBeingErnest Nice use of code snippets in the answer. Can I know if putting the code as CSS in the answer was a deliberate choice or is it the same for HTML/JS etc? I must confess I spent a few confused minutes just clicking theRun code snippetexpecting to see some python output.
– Harsh
Nov 12 '17 at 0:13
@Harsh Sorry for the confusion. I misused this css/javascrip feature to hide the code in order not to clutter the answer. This allows to clearly see all options in the answer, but at the same time gives a complete example for anyone in need of it (I always like to provide mcves to make some command unambiguous.) Unfortunately this "Hide Code" feature is not available for other languages like python.
– ImportanceOfBeingErnest
Nov 12 '17 at 9:02
The first (slow) method above is very useful for on-line animations, i.e., for when you are generating data frame by frame, rather than having it all a priori.
– Novak
Jan 16 '18 at 2:45
add a comment |
Some options you have for animating plots in Jupyter/IPython, using matplotlib:
Using
displayin a loop UseIPython.display.display(fig)to display a figure in the output. Using a loop you would want to clear the output before a new figure is shown. Note that this technique gives in general not so smooth resluts. I would hence advice to use any of the below.import matplotlib.pyplot as plt
import matplotlib.animation
import numpy as np
from IPython.display import display, clear_output
t = np.linspace(0,2*np.pi)
x = np.sin(t)
fig, ax = plt.subplots()
l, = ax.plot([0,2*np.pi],[-1,1])
animate = lambda i: l.set_data(t[:i], x[:i])
for i in range(len(x)):
animate(i)
clear_output(wait=True)
display(fig)
plt.show()%matplotlib notebookUse IPython magic%matplotlib notebookto set the backend to the notebook backend. This will keep the figure alive instead of displaying a static png file and can hence also show animations.
Complete example:%matplotlib notebook
import matplotlib.pyplot as plt
import matplotlib.animation
import numpy as np
t = np.linspace(0,2*np.pi)
x = np.sin(t)
fig, ax = plt.subplots()
l, = ax.plot([0,2*np.pi],[-1,1])
animate = lambda i: l.set_data(t[:i], x[:i])
ani = matplotlib.animation.FuncAnimation(fig, animate, frames=len(t))
plt.show()%matplotlib tkUse IPython magic%matplotlib tkto set the backend to the tk backend. This will open the figure in a new plotting window, which is interactive and can thus also show animations.
Complete example:%matplotlib tk
import matplotlib.pyplot as plt
import matplotlib.animation
import numpy as np
t = np.linspace(0,2*np.pi)
x = np.sin(t)
fig, ax = plt.subplots()
l, = ax.plot([0,2*np.pi],[-1,1])
animate = lambda i: l.set_data(t[:i], x[:i])
ani = matplotlib.animation.FuncAnimation(fig, animate, frames=len(t))
plt.show()Convert animation to mp4 video (option mentionned by @Perfi already):
from IPython.display import HTML
HTML(ani.to_html5_video())or use
plt.rcParams["animation.html"] = "html5"at the beginning of the notebook.
This will require to have ffmpeg video codecs available to convert to HTML5 video. The video is then shown inline. This is therefore compatible with%matplotlib inlinebackend. Complete example:%matplotlib inline
import matplotlib.pyplot as plt
plt.rcParams["animation.html"] = "html5"
import matplotlib.animation
import numpy as np
t = np.linspace(0,2*np.pi)
x = np.sin(t)
fig, ax = plt.subplots()
l, = ax.plot([0,2*np.pi],[-1,1])
animate = lambda i: l.set_data(t[:i], x[:i])
ani = matplotlib.animation.FuncAnimation(fig, animate, frames=len(t))
ani%matplotlib inline
import matplotlib.pyplot as plt
import matplotlib.animation
import numpy as np
t = np.linspace(0,2*np.pi)
x = np.sin(t)
fig, ax = plt.subplots()
l, = ax.plot([0,2*np.pi],[-1,1])
animate = lambda i: l.set_data(t[:i], x[:i])
ani = matplotlib.animation.FuncAnimation(fig, animate, frames=len(t))
from IPython.display import HTML
HTML(ani.to_html5_video())Convert animation to JavaScript:
from IPython.display import HTML
HTML(ani.to_jshtml())or use
plt.rcParams["animation.html"] = "jshtml"at the beginning of the notebook.
This will display the animation as HTML with JavaScript. This highly compatible with most new browsers and also with the%matplotlib inlinebackend. It is available in matplotlib 2.1 or higher.
Complete example:%matplotlib inline
import matplotlib.pyplot as plt
plt.rcParams["animation.html"] = "jshtml"
import matplotlib.animation
import numpy as np
t = np.linspace(0,2*np.pi)
x = np.sin(t)
fig, ax = plt.subplots()
l, = ax.plot([0,2*np.pi],[-1,1])
animate = lambda i: l.set_data(t[:i], x[:i])
ani = matplotlib.animation.FuncAnimation(fig, animate, frames=len(t))
ani%matplotlib inline
import matplotlib.pyplot as plt
import matplotlib.animation
import numpy as np
t = np.linspace(0,2*np.pi)
x = np.sin(t)
fig, ax = plt.subplots()
l, = ax.plot([0,2*np.pi],[-1,1])
animate = lambda i: l.set_data(t[:i], x[:i])
ani = matplotlib.animation.FuncAnimation(fig, animate, frames=len(t))
from IPython.display import HTML
HTML(ani.to_jshtml())
Quick question, since I don't understand these backend things at all, how would you recommend learning about them? Is there a book, or some general topic that I can look up, in order to study whatever is necessary to understand them? Or perhaps a better question: In what class would you learn about these, if you were taking a CompSci course?
– Addem
Oct 23 '17 at 22:58
I have no idea about CompSci courses. I guess you learn about them by using them. There is a matplotlib page about them. Concerning Jupyter, there is this page as introduction.
– ImportanceOfBeingErnest
Oct 24 '17 at 6:33
Converting animation to JavaScript in matplotlib is a boon, especially as it removes the hassle of installing ffmpeg codecs for someone in a hurry. @ImportanceOfBeingErnest Nice use of code snippets in the answer. Can I know if putting the code as CSS in the answer was a deliberate choice or is it the same for HTML/JS etc? I must confess I spent a few confused minutes just clicking theRun code snippetexpecting to see some python output.
– Harsh
Nov 12 '17 at 0:13
@Harsh Sorry for the confusion. I misused this css/javascrip feature to hide the code in order not to clutter the answer. This allows to clearly see all options in the answer, but at the same time gives a complete example for anyone in need of it (I always like to provide mcves to make some command unambiguous.) Unfortunately this "Hide Code" feature is not available for other languages like python.
– ImportanceOfBeingErnest
Nov 12 '17 at 9:02
The first (slow) method above is very useful for on-line animations, i.e., for when you are generating data frame by frame, rather than having it all a priori.
– Novak
Jan 16 '18 at 2:45
add a comment |
Some options you have for animating plots in Jupyter/IPython, using matplotlib:
Using
displayin a loop UseIPython.display.display(fig)to display a figure in the output. Using a loop you would want to clear the output before a new figure is shown. Note that this technique gives in general not so smooth resluts. I would hence advice to use any of the below.import matplotlib.pyplot as plt
import matplotlib.animation
import numpy as np
from IPython.display import display, clear_output
t = np.linspace(0,2*np.pi)
x = np.sin(t)
fig, ax = plt.subplots()
l, = ax.plot([0,2*np.pi],[-1,1])
animate = lambda i: l.set_data(t[:i], x[:i])
for i in range(len(x)):
animate(i)
clear_output(wait=True)
display(fig)
plt.show()%matplotlib notebookUse IPython magic%matplotlib notebookto set the backend to the notebook backend. This will keep the figure alive instead of displaying a static png file and can hence also show animations.
Complete example:%matplotlib notebook
import matplotlib.pyplot as plt
import matplotlib.animation
import numpy as np
t = np.linspace(0,2*np.pi)
x = np.sin(t)
fig, ax = plt.subplots()
l, = ax.plot([0,2*np.pi],[-1,1])
animate = lambda i: l.set_data(t[:i], x[:i])
ani = matplotlib.animation.FuncAnimation(fig, animate, frames=len(t))
plt.show()%matplotlib tkUse IPython magic%matplotlib tkto set the backend to the tk backend. This will open the figure in a new plotting window, which is interactive and can thus also show animations.
Complete example:%matplotlib tk
import matplotlib.pyplot as plt
import matplotlib.animation
import numpy as np
t = np.linspace(0,2*np.pi)
x = np.sin(t)
fig, ax = plt.subplots()
l, = ax.plot([0,2*np.pi],[-1,1])
animate = lambda i: l.set_data(t[:i], x[:i])
ani = matplotlib.animation.FuncAnimation(fig, animate, frames=len(t))
plt.show()Convert animation to mp4 video (option mentionned by @Perfi already):
from IPython.display import HTML
HTML(ani.to_html5_video())or use
plt.rcParams["animation.html"] = "html5"at the beginning of the notebook.
This will require to have ffmpeg video codecs available to convert to HTML5 video. The video is then shown inline. This is therefore compatible with%matplotlib inlinebackend. Complete example:%matplotlib inline
import matplotlib.pyplot as plt
plt.rcParams["animation.html"] = "html5"
import matplotlib.animation
import numpy as np
t = np.linspace(0,2*np.pi)
x = np.sin(t)
fig, ax = plt.subplots()
l, = ax.plot([0,2*np.pi],[-1,1])
animate = lambda i: l.set_data(t[:i], x[:i])
ani = matplotlib.animation.FuncAnimation(fig, animate, frames=len(t))
ani%matplotlib inline
import matplotlib.pyplot as plt
import matplotlib.animation
import numpy as np
t = np.linspace(0,2*np.pi)
x = np.sin(t)
fig, ax = plt.subplots()
l, = ax.plot([0,2*np.pi],[-1,1])
animate = lambda i: l.set_data(t[:i], x[:i])
ani = matplotlib.animation.FuncAnimation(fig, animate, frames=len(t))
from IPython.display import HTML
HTML(ani.to_html5_video())Convert animation to JavaScript:
from IPython.display import HTML
HTML(ani.to_jshtml())or use
plt.rcParams["animation.html"] = "jshtml"at the beginning of the notebook.
This will display the animation as HTML with JavaScript. This highly compatible with most new browsers and also with the%matplotlib inlinebackend. It is available in matplotlib 2.1 or higher.
Complete example:%matplotlib inline
import matplotlib.pyplot as plt
plt.rcParams["animation.html"] = "jshtml"
import matplotlib.animation
import numpy as np
t = np.linspace(0,2*np.pi)
x = np.sin(t)
fig, ax = plt.subplots()
l, = ax.plot([0,2*np.pi],[-1,1])
animate = lambda i: l.set_data(t[:i], x[:i])
ani = matplotlib.animation.FuncAnimation(fig, animate, frames=len(t))
ani%matplotlib inline
import matplotlib.pyplot as plt
import matplotlib.animation
import numpy as np
t = np.linspace(0,2*np.pi)
x = np.sin(t)
fig, ax = plt.subplots()
l, = ax.plot([0,2*np.pi],[-1,1])
animate = lambda i: l.set_data(t[:i], x[:i])
ani = matplotlib.animation.FuncAnimation(fig, animate, frames=len(t))
from IPython.display import HTML
HTML(ani.to_jshtml())
Some options you have for animating plots in Jupyter/IPython, using matplotlib:
Using
displayin a loop UseIPython.display.display(fig)to display a figure in the output. Using a loop you would want to clear the output before a new figure is shown. Note that this technique gives in general not so smooth resluts. I would hence advice to use any of the below.import matplotlib.pyplot as plt
import matplotlib.animation
import numpy as np
from IPython.display import display, clear_output
t = np.linspace(0,2*np.pi)
x = np.sin(t)
fig, ax = plt.subplots()
l, = ax.plot([0,2*np.pi],[-1,1])
animate = lambda i: l.set_data(t[:i], x[:i])
for i in range(len(x)):
animate(i)
clear_output(wait=True)
display(fig)
plt.show()%matplotlib notebookUse IPython magic%matplotlib notebookto set the backend to the notebook backend. This will keep the figure alive instead of displaying a static png file and can hence also show animations.
Complete example:%matplotlib notebook
import matplotlib.pyplot as plt
import matplotlib.animation
import numpy as np
t = np.linspace(0,2*np.pi)
x = np.sin(t)
fig, ax = plt.subplots()
l, = ax.plot([0,2*np.pi],[-1,1])
animate = lambda i: l.set_data(t[:i], x[:i])
ani = matplotlib.animation.FuncAnimation(fig, animate, frames=len(t))
plt.show()%matplotlib tkUse IPython magic%matplotlib tkto set the backend to the tk backend. This will open the figure in a new plotting window, which is interactive and can thus also show animations.
Complete example:%matplotlib tk
import matplotlib.pyplot as plt
import matplotlib.animation
import numpy as np
t = np.linspace(0,2*np.pi)
x = np.sin(t)
fig, ax = plt.subplots()
l, = ax.plot([0,2*np.pi],[-1,1])
animate = lambda i: l.set_data(t[:i], x[:i])
ani = matplotlib.animation.FuncAnimation(fig, animate, frames=len(t))
plt.show()Convert animation to mp4 video (option mentionned by @Perfi already):
from IPython.display import HTML
HTML(ani.to_html5_video())or use
plt.rcParams["animation.html"] = "html5"at the beginning of the notebook.
This will require to have ffmpeg video codecs available to convert to HTML5 video. The video is then shown inline. This is therefore compatible with%matplotlib inlinebackend. Complete example:%matplotlib inline
import matplotlib.pyplot as plt
plt.rcParams["animation.html"] = "html5"
import matplotlib.animation
import numpy as np
t = np.linspace(0,2*np.pi)
x = np.sin(t)
fig, ax = plt.subplots()
l, = ax.plot([0,2*np.pi],[-1,1])
animate = lambda i: l.set_data(t[:i], x[:i])
ani = matplotlib.animation.FuncAnimation(fig, animate, frames=len(t))
ani%matplotlib inline
import matplotlib.pyplot as plt
import matplotlib.animation
import numpy as np
t = np.linspace(0,2*np.pi)
x = np.sin(t)
fig, ax = plt.subplots()
l, = ax.plot([0,2*np.pi],[-1,1])
animate = lambda i: l.set_data(t[:i], x[:i])
ani = matplotlib.animation.FuncAnimation(fig, animate, frames=len(t))
from IPython.display import HTML
HTML(ani.to_html5_video())Convert animation to JavaScript:
from IPython.display import HTML
HTML(ani.to_jshtml())or use
plt.rcParams["animation.html"] = "jshtml"at the beginning of the notebook.
This will display the animation as HTML with JavaScript. This highly compatible with most new browsers and also with the%matplotlib inlinebackend. It is available in matplotlib 2.1 or higher.
Complete example:%matplotlib inline
import matplotlib.pyplot as plt
plt.rcParams["animation.html"] = "jshtml"
import matplotlib.animation
import numpy as np
t = np.linspace(0,2*np.pi)
x = np.sin(t)
fig, ax = plt.subplots()
l, = ax.plot([0,2*np.pi],[-1,1])
animate = lambda i: l.set_data(t[:i], x[:i])
ani = matplotlib.animation.FuncAnimation(fig, animate, frames=len(t))
ani%matplotlib inline
import matplotlib.pyplot as plt
import matplotlib.animation
import numpy as np
t = np.linspace(0,2*np.pi)
x = np.sin(t)
fig, ax = plt.subplots()
l, = ax.plot([0,2*np.pi],[-1,1])
animate = lambda i: l.set_data(t[:i], x[:i])
ani = matplotlib.animation.FuncAnimation(fig, animate, frames=len(t))
from IPython.display import HTML
HTML(ani.to_jshtml())
import matplotlib.pyplot as plt
import matplotlib.animation
import numpy as np
from IPython.display import display, clear_output
t = np.linspace(0,2*np.pi)
x = np.sin(t)
fig, ax = plt.subplots()
l, = ax.plot([0,2*np.pi],[-1,1])
animate = lambda i: l.set_data(t[:i], x[:i])
for i in range(len(x)):
animate(i)
clear_output(wait=True)
display(fig)
plt.show()import matplotlib.pyplot as plt
import matplotlib.animation
import numpy as np
from IPython.display import display, clear_output
t = np.linspace(0,2*np.pi)
x = np.sin(t)
fig, ax = plt.subplots()
l, = ax.plot([0,2*np.pi],[-1,1])
animate = lambda i: l.set_data(t[:i], x[:i])
for i in range(len(x)):
animate(i)
clear_output(wait=True)
display(fig)
plt.show()%matplotlib notebook
import matplotlib.pyplot as plt
import matplotlib.animation
import numpy as np
t = np.linspace(0,2*np.pi)
x = np.sin(t)
fig, ax = plt.subplots()
l, = ax.plot([0,2*np.pi],[-1,1])
animate = lambda i: l.set_data(t[:i], x[:i])
ani = matplotlib.animation.FuncAnimation(fig, animate, frames=len(t))
plt.show()%matplotlib notebook
import matplotlib.pyplot as plt
import matplotlib.animation
import numpy as np
t = np.linspace(0,2*np.pi)
x = np.sin(t)
fig, ax = plt.subplots()
l, = ax.plot([0,2*np.pi],[-1,1])
animate = lambda i: l.set_data(t[:i], x[:i])
ani = matplotlib.animation.FuncAnimation(fig, animate, frames=len(t))
plt.show()%matplotlib tk
import matplotlib.pyplot as plt
import matplotlib.animation
import numpy as np
t = np.linspace(0,2*np.pi)
x = np.sin(t)
fig, ax = plt.subplots()
l, = ax.plot([0,2*np.pi],[-1,1])
animate = lambda i: l.set_data(t[:i], x[:i])
ani = matplotlib.animation.FuncAnimation(fig, animate, frames=len(t))
plt.show()%matplotlib tk
import matplotlib.pyplot as plt
import matplotlib.animation
import numpy as np
t = np.linspace(0,2*np.pi)
x = np.sin(t)
fig, ax = plt.subplots()
l, = ax.plot([0,2*np.pi],[-1,1])
animate = lambda i: l.set_data(t[:i], x[:i])
ani = matplotlib.animation.FuncAnimation(fig, animate, frames=len(t))
plt.show()%matplotlib inline
import matplotlib.pyplot as plt
plt.rcParams["animation.html"] = "html5"
import matplotlib.animation
import numpy as np
t = np.linspace(0,2*np.pi)
x = np.sin(t)
fig, ax = plt.subplots()
l, = ax.plot([0,2*np.pi],[-1,1])
animate = lambda i: l.set_data(t[:i], x[:i])
ani = matplotlib.animation.FuncAnimation(fig, animate, frames=len(t))
ani%matplotlib inline
import matplotlib.pyplot as plt
plt.rcParams["animation.html"] = "html5"
import matplotlib.animation
import numpy as np
t = np.linspace(0,2*np.pi)
x = np.sin(t)
fig, ax = plt.subplots()
l, = ax.plot([0,2*np.pi],[-1,1])
animate = lambda i: l.set_data(t[:i], x[:i])
ani = matplotlib.animation.FuncAnimation(fig, animate, frames=len(t))
ani%matplotlib inline
import matplotlib.pyplot as plt
import matplotlib.animation
import numpy as np
t = np.linspace(0,2*np.pi)
x = np.sin(t)
fig, ax = plt.subplots()
l, = ax.plot([0,2*np.pi],[-1,1])
animate = lambda i: l.set_data(t[:i], x[:i])
ani = matplotlib.animation.FuncAnimation(fig, animate, frames=len(t))
from IPython.display import HTML
HTML(ani.to_html5_video())%matplotlib inline
import matplotlib.pyplot as plt
import matplotlib.animation
import numpy as np
t = np.linspace(0,2*np.pi)
x = np.sin(t)
fig, ax = plt.subplots()
l, = ax.plot([0,2*np.pi],[-1,1])
animate = lambda i: l.set_data(t[:i], x[:i])
ani = matplotlib.animation.FuncAnimation(fig, animate, frames=len(t))
from IPython.display import HTML
HTML(ani.to_html5_video())%matplotlib inline
import matplotlib.pyplot as plt
plt.rcParams["animation.html"] = "jshtml"
import matplotlib.animation
import numpy as np
t = np.linspace(0,2*np.pi)
x = np.sin(t)
fig, ax = plt.subplots()
l, = ax.plot([0,2*np.pi],[-1,1])
animate = lambda i: l.set_data(t[:i], x[:i])
ani = matplotlib.animation.FuncAnimation(fig, animate, frames=len(t))
ani%matplotlib inline
import matplotlib.pyplot as plt
plt.rcParams["animation.html"] = "jshtml"
import matplotlib.animation
import numpy as np
t = np.linspace(0,2*np.pi)
x = np.sin(t)
fig, ax = plt.subplots()
l, = ax.plot([0,2*np.pi],[-1,1])
animate = lambda i: l.set_data(t[:i], x[:i])
ani = matplotlib.animation.FuncAnimation(fig, animate, frames=len(t))
ani%matplotlib inline
import matplotlib.pyplot as plt
import matplotlib.animation
import numpy as np
t = np.linspace(0,2*np.pi)
x = np.sin(t)
fig, ax = plt.subplots()
l, = ax.plot([0,2*np.pi],[-1,1])
animate = lambda i: l.set_data(t[:i], x[:i])
ani = matplotlib.animation.FuncAnimation(fig, animate, frames=len(t))
from IPython.display import HTML
HTML(ani.to_jshtml())%matplotlib inline
import matplotlib.pyplot as plt
import matplotlib.animation
import numpy as np
t = np.linspace(0,2*np.pi)
x = np.sin(t)
fig, ax = plt.subplots()
l, = ax.plot([0,2*np.pi],[-1,1])
animate = lambda i: l.set_data(t[:i], x[:i])
ani = matplotlib.animation.FuncAnimation(fig, animate, frames=len(t))
from IPython.display import HTML
HTML(ani.to_jshtml())edited Jan 26 '18 at 10:06
answered Oct 22 '17 at 19:55
ImportanceOfBeingErnestImportanceOfBeingErnest
159k15 gold badges200 silver badges288 bronze badges
159k15 gold badges200 silver badges288 bronze badges
Quick question, since I don't understand these backend things at all, how would you recommend learning about them? Is there a book, or some general topic that I can look up, in order to study whatever is necessary to understand them? Or perhaps a better question: In what class would you learn about these, if you were taking a CompSci course?
– Addem
Oct 23 '17 at 22:58
I have no idea about CompSci courses. I guess you learn about them by using them. There is a matplotlib page about them. Concerning Jupyter, there is this page as introduction.
– ImportanceOfBeingErnest
Oct 24 '17 at 6:33
Converting animation to JavaScript in matplotlib is a boon, especially as it removes the hassle of installing ffmpeg codecs for someone in a hurry. @ImportanceOfBeingErnest Nice use of code snippets in the answer. Can I know if putting the code as CSS in the answer was a deliberate choice or is it the same for HTML/JS etc? I must confess I spent a few confused minutes just clicking theRun code snippetexpecting to see some python output.
– Harsh
Nov 12 '17 at 0:13
@Harsh Sorry for the confusion. I misused this css/javascrip feature to hide the code in order not to clutter the answer. This allows to clearly see all options in the answer, but at the same time gives a complete example for anyone in need of it (I always like to provide mcves to make some command unambiguous.) Unfortunately this "Hide Code" feature is not available for other languages like python.
– ImportanceOfBeingErnest
Nov 12 '17 at 9:02
The first (slow) method above is very useful for on-line animations, i.e., for when you are generating data frame by frame, rather than having it all a priori.
– Novak
Jan 16 '18 at 2:45
add a comment |
Quick question, since I don't understand these backend things at all, how would you recommend learning about them? Is there a book, or some general topic that I can look up, in order to study whatever is necessary to understand them? Or perhaps a better question: In what class would you learn about these, if you were taking a CompSci course?
– Addem
Oct 23 '17 at 22:58
I have no idea about CompSci courses. I guess you learn about them by using them. There is a matplotlib page about them. Concerning Jupyter, there is this page as introduction.
– ImportanceOfBeingErnest
Oct 24 '17 at 6:33
Converting animation to JavaScript in matplotlib is a boon, especially as it removes the hassle of installing ffmpeg codecs for someone in a hurry. @ImportanceOfBeingErnest Nice use of code snippets in the answer. Can I know if putting the code as CSS in the answer was a deliberate choice or is it the same for HTML/JS etc? I must confess I spent a few confused minutes just clicking theRun code snippetexpecting to see some python output.
– Harsh
Nov 12 '17 at 0:13
@Harsh Sorry for the confusion. I misused this css/javascrip feature to hide the code in order not to clutter the answer. This allows to clearly see all options in the answer, but at the same time gives a complete example for anyone in need of it (I always like to provide mcves to make some command unambiguous.) Unfortunately this "Hide Code" feature is not available for other languages like python.
– ImportanceOfBeingErnest
Nov 12 '17 at 9:02
The first (slow) method above is very useful for on-line animations, i.e., for when you are generating data frame by frame, rather than having it all a priori.
– Novak
Jan 16 '18 at 2:45
Quick question, since I don't understand these backend things at all, how would you recommend learning about them? Is there a book, or some general topic that I can look up, in order to study whatever is necessary to understand them? Or perhaps a better question: In what class would you learn about these, if you were taking a CompSci course?
– Addem
Oct 23 '17 at 22:58
Quick question, since I don't understand these backend things at all, how would you recommend learning about them? Is there a book, or some general topic that I can look up, in order to study whatever is necessary to understand them? Or perhaps a better question: In what class would you learn about these, if you were taking a CompSci course?
– Addem
Oct 23 '17 at 22:58
I have no idea about CompSci courses. I guess you learn about them by using them. There is a matplotlib page about them. Concerning Jupyter, there is this page as introduction.
– ImportanceOfBeingErnest
Oct 24 '17 at 6:33
I have no idea about CompSci courses. I guess you learn about them by using them. There is a matplotlib page about them. Concerning Jupyter, there is this page as introduction.
– ImportanceOfBeingErnest
Oct 24 '17 at 6:33
Converting animation to JavaScript in matplotlib is a boon, especially as it removes the hassle of installing ffmpeg codecs for someone in a hurry. @ImportanceOfBeingErnest Nice use of code snippets in the answer. Can I know if putting the code as CSS in the answer was a deliberate choice or is it the same for HTML/JS etc? I must confess I spent a few confused minutes just clicking the
Run code snippet expecting to see some python output.– Harsh
Nov 12 '17 at 0:13
Converting animation to JavaScript in matplotlib is a boon, especially as it removes the hassle of installing ffmpeg codecs for someone in a hurry. @ImportanceOfBeingErnest Nice use of code snippets in the answer. Can I know if putting the code as CSS in the answer was a deliberate choice or is it the same for HTML/JS etc? I must confess I spent a few confused minutes just clicking the
Run code snippet expecting to see some python output.– Harsh
Nov 12 '17 at 0:13
@Harsh Sorry for the confusion. I misused this css/javascrip feature to hide the code in order not to clutter the answer. This allows to clearly see all options in the answer, but at the same time gives a complete example for anyone in need of it (I always like to provide mcves to make some command unambiguous.) Unfortunately this "Hide Code" feature is not available for other languages like python.
– ImportanceOfBeingErnest
Nov 12 '17 at 9:02
@Harsh Sorry for the confusion. I misused this css/javascrip feature to hide the code in order not to clutter the answer. This allows to clearly see all options in the answer, but at the same time gives a complete example for anyone in need of it (I always like to provide mcves to make some command unambiguous.) Unfortunately this "Hide Code" feature is not available for other languages like python.
– ImportanceOfBeingErnest
Nov 12 '17 at 9:02
The first (slow) method above is very useful for on-line animations, i.e., for when you are generating data frame by frame, rather than having it all a priori.
– Novak
Jan 16 '18 at 2:45
The first (slow) method above is very useful for on-line animations, i.e., for when you are generating data frame by frame, rather than having it all a priori.
– Novak
Jan 16 '18 at 2:45
add a comment |
You may find this tutorial interesting.
If you can turn what you need into a matplotlib animation, and I'm fairly sure from your description that it's possible, you can then use
from matplotlib import rc, animation
rc('animation', html='html5')
and display your animation using
anim = animation.FuncAnimation(fig, animate, init_func=init,
frames=N, interval=20, blit=True)
anim
Might come in handy!
add a comment |
You may find this tutorial interesting.
If you can turn what you need into a matplotlib animation, and I'm fairly sure from your description that it's possible, you can then use
from matplotlib import rc, animation
rc('animation', html='html5')
and display your animation using
anim = animation.FuncAnimation(fig, animate, init_func=init,
frames=N, interval=20, blit=True)
anim
Might come in handy!
add a comment |
You may find this tutorial interesting.
If you can turn what you need into a matplotlib animation, and I'm fairly sure from your description that it's possible, you can then use
from matplotlib import rc, animation
rc('animation', html='html5')
and display your animation using
anim = animation.FuncAnimation(fig, animate, init_func=init,
frames=N, interval=20, blit=True)
anim
Might come in handy!
You may find this tutorial interesting.
If you can turn what you need into a matplotlib animation, and I'm fairly sure from your description that it's possible, you can then use
from matplotlib import rc, animation
rc('animation', html='html5')
and display your animation using
anim = animation.FuncAnimation(fig, animate, init_func=init,
frames=N, interval=20, blit=True)
anim
Might come in handy!
answered Jun 9 '16 at 16:13
PerfiPerfi
7748 silver badges22 bronze badges
7748 silver badges22 bronze badges
add a comment |
add a comment |
I had a similar problem, and this question helped me get started. I put together a notebook that illustrates using FuncAnimation along with good explanations of why the notebook does some things the way it does. It also has links to instructions on FFmpeg. It also has links to the examples I used in developing and understanding of animations. You can view my contribution at:
Animation Illustration
For your question, you might find interactive sliders a better tool. I also created a notebook which demonstrates interactive widgets in Jupyter. It is available here; however, the interactive parts don't work there.
Both are available in a GitHub Repostory
add a comment |
I had a similar problem, and this question helped me get started. I put together a notebook that illustrates using FuncAnimation along with good explanations of why the notebook does some things the way it does. It also has links to instructions on FFmpeg. It also has links to the examples I used in developing and understanding of animations. You can view my contribution at:
Animation Illustration
For your question, you might find interactive sliders a better tool. I also created a notebook which demonstrates interactive widgets in Jupyter. It is available here; however, the interactive parts don't work there.
Both are available in a GitHub Repostory
add a comment |
I had a similar problem, and this question helped me get started. I put together a notebook that illustrates using FuncAnimation along with good explanations of why the notebook does some things the way it does. It also has links to instructions on FFmpeg. It also has links to the examples I used in developing and understanding of animations. You can view my contribution at:
Animation Illustration
For your question, you might find interactive sliders a better tool. I also created a notebook which demonstrates interactive widgets in Jupyter. It is available here; however, the interactive parts don't work there.
Both are available in a GitHub Repostory
I had a similar problem, and this question helped me get started. I put together a notebook that illustrates using FuncAnimation along with good explanations of why the notebook does some things the way it does. It also has links to instructions on FFmpeg. It also has links to the examples I used in developing and understanding of animations. You can view my contribution at:
Animation Illustration
For your question, you might find interactive sliders a better tool. I also created a notebook which demonstrates interactive widgets in Jupyter. It is available here; however, the interactive parts don't work there.
Both are available in a GitHub Repostory
answered Nov 1 '16 at 15:51
Will HolmesWill Holmes
512 bronze badges
512 bronze badges
add a comment |
add a comment |
Jupyter widgets is a good way of displaying animations. The code below displays an animated gif.....
from ipywidgets import Image
from IPython import display
animatedGif = "animatedGifs/01-progress.gif" #path relative to your notebook
file = open(animatedGif , "rb")
image = file.read()
progress= Image(
value=image,
format='gif',
width=100,
height=100)
display.display(progress)
You can close this animation using:
progress.close()
N.B. I found a few nice animated gifs from http://www.downgraf.com/inspiration/25-beautiful-loading-bar-design-examples-gif-animated/.
add a comment |
Jupyter widgets is a good way of displaying animations. The code below displays an animated gif.....
from ipywidgets import Image
from IPython import display
animatedGif = "animatedGifs/01-progress.gif" #path relative to your notebook
file = open(animatedGif , "rb")
image = file.read()
progress= Image(
value=image,
format='gif',
width=100,
height=100)
display.display(progress)
You can close this animation using:
progress.close()
N.B. I found a few nice animated gifs from http://www.downgraf.com/inspiration/25-beautiful-loading-bar-design-examples-gif-animated/.
add a comment |
Jupyter widgets is a good way of displaying animations. The code below displays an animated gif.....
from ipywidgets import Image
from IPython import display
animatedGif = "animatedGifs/01-progress.gif" #path relative to your notebook
file = open(animatedGif , "rb")
image = file.read()
progress= Image(
value=image,
format='gif',
width=100,
height=100)
display.display(progress)
You can close this animation using:
progress.close()
N.B. I found a few nice animated gifs from http://www.downgraf.com/inspiration/25-beautiful-loading-bar-design-examples-gif-animated/.
Jupyter widgets is a good way of displaying animations. The code below displays an animated gif.....
from ipywidgets import Image
from IPython import display
animatedGif = "animatedGifs/01-progress.gif" #path relative to your notebook
file = open(animatedGif , "rb")
image = file.read()
progress= Image(
value=image,
format='gif',
width=100,
height=100)
display.display(progress)
You can close this animation using:
progress.close()
N.B. I found a few nice animated gifs from http://www.downgraf.com/inspiration/25-beautiful-loading-bar-design-examples-gif-animated/.
answered Jun 13 '17 at 12:14
DougRDougR
1,2131 gold badge13 silver badges18 bronze badges
1,2131 gold badge13 silver badges18 bronze badges
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f35532498%2fanimation-in-ipython-notebook%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
There is JSAnimation, but it requires extra installation. You can replace an output such as a plot with IPython.display.clear_output, but it won't be smooth enough to properly animate something.
– Thomas K
May 23 '16 at 10:32
JSAnimation does not require extra installation anymore. It has been merged into matplotlib since version 2.1. Usage is shown in the last snippet in answer by @ImportanceOfBeingErnest.
– Harsh
Nov 11 '17 at 23:54