2

The Problem

I'm trying to create a diagram that is similar to this diagram generated by the matlab command waterfall():enter image description here

The data for it is stored in a csv file. In this case it's 129 columns of data, the first one is just an index, the others contain the data for the 128 lines. The data used in the above image can be found in this pastebin.


What I've Tried

\documentclass[crop, tikz]{standalone}
\usepackage{pgfplots}
\pgfplotstableread[col sep = comma]{data.csv}\mydata
\begin{document}
\begin{tikzpicture}
  \begin{axis}[
    no markers,
    xmin = 0, xmax = 140,
    ymin = 0, ymax = 150,
    zmin = 0, zmax = 0.07,
    x dir = reverse]
    \addplot table[x = 1, y index = {0}, z index = {1}]{\mydata};
    \addplot table[x = 2, y index = {0}, z index = {2}]{\mydata};
  \end{axis}
\end{tikzpicture}
\end{document}

Basically, I'm trying to give each line a fixed x value and have it read the y and z values from the csv. For now I'm trying to add a few lines manually. Later I'd like to generate the addplot entries using some kind of for loop that.

percusse
  • 157,807
youR.Fate
  • 141

1 Answers1

2

Using the thread supplied by @Jake I managed to solve the issue. I needed to import pgfplotstable. Then I can itterate using pgfplotsinvokeforeach and x expr. The working solution looks like this:

\documentclass[crop, tikz]{standalone}
\usepackage{pgfplots,pgfplotstable}
\pgfplotstableread[col sep = comma]{data.csv}\mydata
\begin{document}
\begin{tikzpicture}
  \begin{axis}[
    no markers,
    xmin = 0, xmax = 140,
    xlabel = {Polyphase},
    ymin = 0, ymax = 150,
    ylabel = {sample\#},
    zmin = 0, zmax = 0.07,
    zlabel = {Magnitude},
    x dir = reverse]
    \pgfplotsinvokeforeach{1,2,...,128}{
    \addplot3 table[x expr = #1, y index = {0}, z index = {#1}]{\mydata};}
  \end{axis}
\end{tikzpicture}
\end{document}

And it produces the following output: enter image description here

This still requires some fine tuning, but it works. For this to work I also had to increase the TeX memory. To increase the TeX memory in a miktex system open the relevant config file using initexmf --edit-config-file pdflatex. Then add the following values, edit them to your liking if you want:

pool_size=5000000
main_memory=6000000
extra_mem_bot=2000000
font_mem_size=2000000

Then remake the format files using initexmf --dump=pdflatex. Source.

youR.Fate
  • 141