I have a huge sparse matrix of about 10.000 x 10.000 entries with 60.000 non-zero entries. I'd like to visualize the pattern, that means zero entries are ignored and non-zero entries are marked with a small circle, maybe colored by its value.

Just printing a pixel for each entry is not enough, as the image would be scaled down and the result barely visible.

Something like Matlab's spy function would be great.

  • 1
    spy in matlab and \includegraphics? – percusse Jan 11 '17 at 9:57
  • @percusse Definitely not. I'd like to load the data from an external file and make all the processing / visalization with TikZ. That can be scripted, is better in a version control etc. – usr1234567 Jan 11 '17 at 10:03
  • 1
    That big matrix is just impossible with TeX. – percusse Jan 11 '17 at 10:04
  • 1
    I would generate a file with 60000 lines with x,y,value entries (with a script or whatever) and then try to plot a scatter graphic. Disclaimer: I do not know if 60k line is manageable... never tried. – Rmano Jan 11 '17 at 10:23
  • 1

Something to try on. It uses tikz and pgfplotstable to fetch the data. It iterates through the table, tough you have to inform the table size beforehand in \nrows and \ncols. I have no idea about performance for big data sets, likely it will be bad (as expected).

The relationship between value and Format/Color is yours to make. Though as percusse said, 10 000x 10 000 Matrix is just too big...


1   2   3   4   5
6   6   8   5   4
1   0   8   5   1
1   2   0   4   5
6   6   8   5   4
1   0   8   5   1
\foreach \i in {0,...,\nrows}{
    \foreach \j in {0,...,\ncols}{
    \node[circle, minimum size=.5pt, inner sep=0pt, fill=red!\pgfplotsretval!purple, opacity=0.\pgfplotsretval] at (\j pt,-\i pt) {};

enter image description here

Making a 60x60 Matrix with "random" integers from 0 to 50 and using the above MWE I got this:

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.