https://github.com/dylanwal/plotly_gif
Generate .gif from your Plotly figures
https://github.com/dylanwal/plotly_gif
gif gifs plotly plotting plotting-in-python python
Last synced: 5 months ago
JSON representation
Generate .gif from your Plotly figures
- Host: GitHub
- URL: https://github.com/dylanwal/plotly_gif
- Owner: dylanwal
- License: bsd-3-clause
- Created: 2022-01-06T00:27:14.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2023-04-10T12:38:56.000Z (over 2 years ago)
- Last Synced: 2025-03-31T03:15:11.670Z (6 months ago)
- Topics: gif, gifs, plotly, plotting, plotting-in-python, python
- Language: Python
- Homepage:
- Size: 2.27 MB
- Stars: 19
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Plotly-gif
---
---


A simple python package to generate .gif from your plotly figures. It works for both 2D and 3D figures. It can even
create_gif motion for you in 3D plots.## Installation
```
pip install plotly-gif
```### Dependencies
If you are already using plotly, then you should be good. But, just in case, these are the dependencies:
* [plotly](https://github.com/plotly/plotly.py) (5.9.0)
* Plots molecules
* [kaleido](https://github.com/plotly/Kaleido) (0.1.0post1)
* Converts plotly graphs to images (png, svg, etc.)
* I am not using the most recent version of kaleido as it does not play nice with my computer. Try the newest
version, but if you are having issues install this specific version.
* [Pillow](https://github.com/python-pillow/Pillow) (9.2.0)
* Used to convert png to gif.
* [numpy](https://github.com/numpy/numpy) (1.23.1)
* Used for math
---
## UsageThere are three common methods:
### Built-in Functions/ Macros
Currently, we have the follow:
* two_d_time_series
* three_d_scatter_rotate
* more to come... or submit your own```python
import plotly.graph_objs as go
from plotly_gif import GIF, two_d_time_seriesfig = go.Figure()
# add your traces()
# add your formatting()gif = GIF()
two_d_time_series(gif, fig)```
### Decorator
If you have a function that is changing the `go.Figure' with each loop, you can add the decorator to the func.
```python
import plotly.graph_objs as go
from plotly_gif import GIF, capturegif = GIF()
@capture(gif)
def plot_(x_, y_):
fig = go.Figure()
# add your traces()
# add your formatting()
return figgif.create_gif() # generate gif
```### In-Line
This very similar to the decorator option, but you can call the image capture function directly.```python
import plotly.graph_objs as go
from plotly_gif import GIF, capturegif = GIF()
def plot_(x_, y_):
fig = go.Figure()
# add your traces()
# add your formatting()
gif.create_image(fig) # create_gif image for gif
return figgif.create_gif() # generate gif
```---
## Examples
See examples folder

### Time to generate gif (60 images per gif)
* Simple 2D plots with small data sets (100 pts): ~10 sec
* Simple 3D plots with small data sets (100 pts): ~1.5 min## Warning
* If your code 'hangs' or 'gets stuck and doesn't complete' try changing kaleido versions `pip install kaleido==0.1.0post1`