2

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.

6
  • 1
    spy in matlab and \includegraphics?
    – percusse
    Commented Jan 11, 2017 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
    Commented Jan 11, 2017 at 10:03
  • 1
    That big matrix is just impossible with TeX.
    – percusse
    Commented Jan 11, 2017 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
    Commented Jan 11, 2017 at 10:23
  • 1
    tex.stackexchange.com/questions/305250/…
    – Rmano
    Commented Jan 11, 2017 at 10:27

1 Answer 1

5

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...

MWE

\documentclass[margin=3mm]{standalone}
\usepackage{tikz,pgfplotstable,filecontents}
\begin{filecontents}{data-table.dat}
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
\end{filecontents}
\pgfplotstableread{data-table.dat}\mytable
\def\nrows{5}
\def\ncols{4}
\begin{document}
\begin{tikzpicture}
\foreach \i in {0,...,\nrows}{
    \foreach \j in {0,...,\ncols}{
    \pgfplotstablegetelem{\i}{\j}\of\mytable
    \ifnum\pgfplotsretval=0\relax\else
    \node[circle, minimum size=.5pt, inner sep=0pt, fill=red!\pgfplotsretval!purple, opacity=0.\pgfplotsretval] at (\j pt,-\i pt) {};
    \fi
    };
};
\end{tikzpicture}
\end{document}

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

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .