Search code examples
pythonmatrixmatplotlibsimilarity

Memory error when trying to plot a matrix with matplotlib


I have a square matrix:

print(len(similarity_matrix)) #display 26003

I'm trying to plot a matrix like:

enter image description here

so I used matplolib:

plt.matshow(similarity_matrix)
plot.show()

But I have a memory error. How can I display my matrix?


Solution

  • The figure produced by a 10000 by 10000 matrix takes 2.6 GB of memory. Suppose this scales linearly with the number of points, a 26000 by 26000 matrix would take 17 GB of memory. (I haven't tested because I only have 16 GB available)

    Do you have more than 17 GB of memory available?

    Another aspect may be that a usual screen has something like 2 million pixels. So it does make little sense wanting to display 670 million pixels on it.