Reputation: 470
I'm building an animated heatmap in python with plotly (just like what's done here).
I'd just like to make the transition quicker (I have a thousand step).
Here's the code from @rpanai I'd like to adapt
import numpy as np
import plotly.graph_objs as go
N = 50
M = np.random.random((N, 10, 10))
fig = go.Figure(
data=[go.Heatmap(z=M[0])],
layout=go.Layout(
title="Frame 0",
updatemenus=[dict(
type="buttons",
buttons=[dict(label="Play",
method="animate",
args=[None])])]
),
frames=[go.Frame(data=[go.Heatmap(z=M[i])],
layout=go.Layout(title_text=f"Frame {i}"))
for i in range(1, N)]
)
fig.show()
Thanks!
Upvotes: 0
Views: 898
Reputation: 61084
Just replace:
args=[None])])]
with:
args=[None, {"frame": {"duration": 1000, "redraw": True},}])])]
And change 1000
(that's millisenconds) to a duration that suits your needs.
import numpy as np
import plotly.graph_objs as go
N = 50
M = np.random.random((N, 10, 10))
fig = go.Figure(
data=[go.Heatmap(z=M[0])],
layout=go.Layout(
title="Frame 0",
updatemenus=[dict(
type="buttons",
buttons=[dict(label="Play",
method="animate",
args=[None, {"frame": {"duration": 2000, "redraw": True},}])])]
),
frames=[go.Frame(data=[go.Heatmap(z=M[i])],
layout=go.Layout(title_text=f"Frame {i}"))
for i in range(1, N)]
)
fig.show()
Upvotes: 1