Why Is Plt.imshow So Much Quicker Than Plt.pcolor ?
I am trying to figure out as much data visualization tools as I can from 2D matrices (bonus points to any other good methods for looking at 2D matrices). I generate a lot of heat
Solution 1:
Answering partially to your question, plt.imshow is much quicker than plt.pcolor because they are not doing similar operations. In fact, they do very different things.
According to the documentation, matplotlib.pyplot.pcolor returns a matplotlib.collections.PolyCollection, which can be slow compared to pcolormesh, which returns a matplotlib.collections.QuadMesh object. imshow, in the other hand, returns a matplotlib.image.AxesImage object. I did a test with pcolor, imshow and pcolormesh:
defimage_gradient(m,n):
"""
Create image arrays
"""
A_m = np.arange(m)[:, None]
A_n = np.arange(n)[None, :]
return(A_m.astype(np.float)+A_n.astype(np.float))
m = 100
n = 100
A_100x100 = image_gradient(m,n)
%time plt.imshow(A_100x100)
%time plt.pcolor(A_100x100)
%time plt.pcolormesh(A_100x100)
and the results I get are:
imshow()CPU times:user76ms,sys:0ns,total:76msWall time:74.4mspcolor()CPU times:user588ms,sys:16ms,total:604msWall time:601mspcolormesh()CPU times:user0ns,sys:4ms,total:4msWall time:2.32ms
Clearly, for this particular example, pcolormesh is the most efficient one.
Post a Comment for "Why Is Plt.imshow So Much Quicker Than Plt.pcolor ?"