I observed during animating heatmaps over Contour plots, it is simply not possible. No matter what trace order I use, the Heatmap always comes below the Contour plot. A demo code to test it out can be as follows.
@shivamshaiv
Since your Frame.data definition contains more than one chart instantiation, you have to set Frame.traces =[0,1] to let plotly.js know that the go.Heatmap, defined as the Frame.data[0], updates fig.data[0], while 'go.Contour` updates fig.data[1].
Hence frame_arr.append(go.Frame(data=[go.Heatmap(z = matrix),go.Contour(z = matrix,opacity=0.5)])) defined at the end of the for loop, must be written: