Black Lives Matter. Please consider donating to Black Girls Code today.
Dash Enterprise delivers an incredible 21x cost savings 💸Download the e-book!

Make a Dynamic Heat Map

I want to make a dynamic heat map which changes with time. I use Python. Can I use the Plotly lib to achieve this?

@YellowClothes You can animate a heatmap using Python Plotly. Here is an example: https://plot.ly/~empet/14138 Click the Play button to activate it…

What about animating a series of heatmaps objects from package plotly.graph_objs.Heatmap ? is that feasible with plotly ?

@nirre Do you mean animating subplots of heatmaps?

I have heatmap plots generated with pltly.graph_objs as in this code snipet:
from plotly.offline import plot
import plotly.graph_objs as go

dirpath = os.path.join(os.getcwd(), “weights_visual_raw_data”)
files = [s for s in os.listdir(dirpath) if os.path.isfile(os.path.join(dirpath, s))]

for i, epoch in enumerate(files):
pkl_file = open(os.path.join(os.getcwd(), “weights_visual_raw_data”, epoch), ‘rb’)
weights = pickle.load(pkl_file)
pkl_file.close()
weights = [x for x in weights if x]
for l, layer in enumerate(weights):
if l >= len(weights)-2:
layer_weights = layer[0]
else:
layer_weights = layer[1]
trace = go.Heatmap(z=layer_weights)
data = [trace]
plot(data, auto_open=False, filename=os.path.join(os.getcwd(),
“weights_dynamic_visualization”,
“layer”+str(l),
“weights_epoch_” + str(i)))
In the end I need to play these plots in animation sequence (maybe with a slider that can iterate between different heamaps)

Yes, you can define the list of frames consisting in data that you plot successively, in the code above.

Could you please demonstrate with a code snippet ? thanks

Also, I’m struggling to understand is whether I need to define columns and a grid for my heatmaps plot or can I just assign each frame with the plot as in
trace = go.Heatmap(z=layer_weights)
data = [trace]
plot(data, auto_open=False, filename=’./’).

In case I need to define columns and grid, how to I define a column for a plotly.graph_objs heatmap object ?