How to export/save an animated bubble chart made with plotly? (For instance, the one was made following the link below) I would like to have it in a gift or some format with better resolution. Thank you in advance.
https://www.kaggle.com/aashita/guide-to-animated-bubble-charts-using-plotly
There is no possibility to do this in plotly. Please use gifmaker
and save every step in the animation as a single picture to later combine them to a gif. Follow this source. Further explanation on how to create animations is provided by plotly here.
The basic way to go would be to integrate this logic into the animation process of your plotly code:
import ImageSequence
import Image
import gifmaker
sequence = []
im = Image.open(....)
# im is your original image
frames = [frame.copy() for frame in ImageSequence.Iterator(im)]
# write GIF animation
fp = open("out.gif", "wb")
gifmaker.makedelta(fp, frames)
fp.close()
If you could provide your actual code, it would be possible to provide a more detailled answer to your question. :)
Another possibility is to use the gif library, which works with matplolib, altair and plotly, and is really straight forward. In this case you would not use a plotly animation. Instead, you define a function that returns a plotly fig and construct a list of figs to pass to gif as an argument.
Your code would look something like this:
import random
import plotly.graph_objects as go
import pandas as pd
import gif
# Pandas DataFrame with random data
df = pd.DataFrame({
't': list(range(10)) * 10,
'x': [random.randint(0, 100) for _ in range(100)],
'y': [random.randint(0, 100) for _ in range(100)]
})
# Gif function definition
@gif.frame
def plot(i):
d = df[df['t'] == i]
fig = go.Figure()
fig.add_trace(go.Scatter(
x=d["x"],
y=d["y"],
mode="markers"
))
fig.update_layout(width=500, height=300)
return fig
# Construct list of frames
frames = []
for i in range(10):
frame = plot(i)
frames.append(frame)
# Save gif from frames with a specific duration for each frame in ms
gif.save(frames, 'example.gif', duration=100)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With