Plotly graph animations do not work in jupyter notebook
See original GitHub issueEnvironment data
- VS Code version: XXX
- Jupyter Extension version (available under the Extensions sidebar): 2020.12.414227025
- Python Extension version (available under the Extensions sidebar): 2020.12.424452561
- OS (Windows | Mac | Linux distro) and version: Windows 10 Home Version 1909 OS Build 18363.1256
- Python and/or Anaconda version: 3.7.6
- Type of virtual environment used (N/A | venv | virtualenv | conda | …): conda
- Jupyter server running: Local | Remote | N/A: Local
Expected behaviour
See: https://plotly.com/python/animations/
Actual behaviour
Animation does not work in Visual Code with plotly.express but works in Google Collaboratory.
The output from VisualCode-jupyter is pasted below. In case of executing the code in Visual Code the graph does not animate and moving the slider has no effect on the graph.
Steps to reproduce:
The code tested for plotting with animation is:
import plotly.express as px
df = px.data.gapminder()
fig = px.scatter(df, x="gdpPercap", y="lifeExp", animation_frame="year", animation_group="country",
size="pop", color="continent", hover_name="country", facet_col="continent",
log_x=True, size_max=45, range_x=[100,100000], range_y=[25,90])
fig.show()
Issue Analytics
- State:
- Created 3 years ago
- Reactions:7
- Comments:52 (23 by maintainers)
Top Results From Across the Web
Graph animations do not work in jupyter notebook in vscode
Animation does not work in Visual Code with plotly.express but works in Google Collaboratory. The output from VisualCode-jupyter is pasted below ...
Read more >Animation not working in jupyter notebook in vscode
An introduction to creating animations with Plotly in Python. The chart can be rendered in a jupyter notebook in vscode, but the animation...
Read more >How to make Plotly graph animated working - Stack Overflow
I tested this code on my jupyter and it works. You need to make plotly offline It opens another tab and show animation....
Read more >Line Chart Animation with Plotly on Jupyter | by Shinichi Okada
In this article, I will try to reproduce one of Our World in Data charts using Plotly animation on Jupyter. The above chart...
Read more >Plotly Animations not working? - Anvil Q&A
Greetings, So I've dug through the docs to no avail, other than to reach ... On a local machine or jupyter notebook the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This seems to be an issue with the ‘plotly_mimetype’ renderer that is used in VS Code per default (‘vscode’ is an alias of 'plotly_mimetype). There are two possible work-arounds depending what Plotly API is used.
If using
plotly.express
, the default renderer can be changed:This will change the renderer to a version that uses the Plotly JS code directly and in online mode.
If using
plotly.graph_objects
you can change the default renderer as above or call out the renderer explicitly duringfig.show()
calls:The renderer can also be changed to ‘notebook’ which is the offline version of ‘notebook_connected’ but it will increase the size of your notebook files. Both methods produce animated and interactive Plotly graphs as expected. Another side effect is that the graphs will also scale with the output cell now.
This method also applies to #4578. #1589 and maybe others.
FWIW, on a recently-updated version of VSCode/this plugin, I can get everything Plotly-related working (
fig.show()
andFigureWidget
) with every interaction except for animations (i.e. panning, zooming, hovering, legend-clicking) without messing with the default renderer.Using
fig.show("notebook")
andfig.show("notebook_connected")
do result in animations working for me.