I have a loop that executes the body about 200 times. In each iteration of the loop, it performs a complex calculation, and then as a debug, I want to create a heat map of the NxM matrix. But generating this heatmap is unbearably slow and significantly slows down the slow algorithm.
My code is line by line:
import numpy
import matplotlib.pyplot as plt
for i in range(200):
matrix = complex_calculation()
plt.set_cmap("gray")
plt.imshow(matrix)
plt.savefig("frame{0}.png".format(i))
The matrix, from numpy, is not huge --- 300 x 600 doubles. Even if I don’t save the number and instead update the screen graph, it’s even slower.
Of course I have to abuse the pipot. (Matlab can do this, no problem.) How do I speed this up?
source
share