2

In the pgfplots groupplot below, I have three sets of data represented by data1, data2 and data3. Each of the data have three subtypes. And I need to plot a graph for each of the subtype. The file data1.dat has data for all the three subtypes. So I manually strip the file into three files as data1-1.dat, data1-2.dat and data1-3.dat.

Is it possible to avoid manually splitting the file and refer to parts of the file. For example to access type1 of data1, I can refer to the first n lines of data1.dat file and to access type2 of data1, I can refer to the next n lines of the same file. The # of lines for each subtype is constant.

\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.10}
\usetikzlibrary{matrix,pgfplots.groupplots}

\begin{document}
\begin{figure*}
\centering
\begin{tikzpicture}[scale=1.0, transform shape]
    \begin{groupplot}[group style={group size= 1 by 3},height=5.9cm,width=8cm,xmode=log,log basis x={2}]
        \nextgroupplot[ylabel={Type 1},xtick=data]
                \addplot[red,semithick,mark=triangle]   table{Data/data1-1.dat};    \label{plots:data1}
                \addplot[blue,semithick,mark=asterisk]  table{Data/data2-1.dat};    \label{plots:data2}
                \addplot[green, semithick,mark=o]           table{Data/data3-1.dat};  \label{plots:data3}
                \coordinate (top) at (rel axis cs:0,1);% coordinate at top of the first plot
        \nextgroupplot[ylabel={Type 2},xtick=data]
                \addplot[red,semithick,mark=triangle]   table{Data/data1-2.dat};
                \addplot[blue,semithick,mark=asterisk]  table{Data/data2-2.dat};
                \addplot[green, semithick,mark=o]           table{Data/data3-2.dat};
        \nextgroupplot[xlabel={Input in powers of 2},ylabel={Type 3},xtick=data]
                \addplot[red,semithick,mark=triangle]   table{Data/data1-3.dat};
                \addplot[blue,semithick,mark=asterisk]  table{Data/data2-3.dat};
                \addplot[green, semithick,mark=o]           table{Data/data3-3.dat};                
                \coordinate (bot) at (rel axis cs:1,0);% coordinate at bottom of the last plot
    \end{groupplot}
    \path (top-|current bounding box.west)-- node[anchor=south,rotate=90] {\small Throughput} (bot-|current bounding box.west);
    \path (top|-current bounding box.north)-- coordinate(legendpos) (bot|-current bounding box.north);
    \matrix[matrix of nodes, anchor=south, draw, inner sep=0.2em, draw] at ([yshift=1ex]legendpos)
    {
        \ref{plots:data1}& data1&[5pt]
        \ref{plots:data2}& data2&[5pt]
        \ref{plots:data3}& data3\\
    };
\end{tikzpicture}
\label{fig:throughput}
\end{figure*}
\end{document}

Output: enter image description here

arunmoezhi
  • 1,270
  • 1
    Did you look at: http://tex.stackexchange.com/questions/199376/how-to-plot-the-first-n-rows-of-a-table-using-pgfplots or http://tex.stackexchange.com/questions/66177/how-can-i-filter-select-data-from-a-table-and-plot-it and similar questions? – Ignasi Sep 09 '14 at 10:28
  • Thanks. The first link worked perfectly. I have marked my question as a duplicate and voted for closure. – arunmoezhi Sep 09 '14 at 17:41

0 Answers0