2

I have a data file with many columns, and I want to plot bwgstar vs servers for n=2. So n is the meta column, servers is on the x-axis, and bwgstar is on the y-axis. I want to do this within the latex document so that I can regenerate the data later.

A shortened version of some data appears below.

  k    n    servers   switches   degree   diameter   bwg      bwgstar   difference   t
  2    2    8         4          2        4          2        2         0            1
  2    3    36        9          4        5          8        6         2            3
  2    4    96        16         6        5          16       16        0            8
  2    5    200       25         8        5          36       30        6            10
  2    6    360       36         10       5          54       54        0            13
  2    7    588       49         12       5          96       84        12           21
  3    2    24        8          3        6          4        4         0            4
  3    3    162       27         6        7          26       22        4            10
  3    4    576       64         9        7          64       64        0            32
2

You can adapt the approach from Filter rows from a table:

\documentclass[border=5mm]{standalone}

\usepackage{filecontents}

\usepackage{pgfplots}
\pgfplotsset{
    discard if not/.style 2 args={
        x filter/.code={
            \ifnum\thisrow{#1}=#2
            \else
                \def\pgfmathresult{nan}
            \fi
        }
    }
}

\begin{filecontents}{data.dat}
k    n    servers   switches   degree   diameter   bwg      bwgstar   difference   t
  2    2    8         4          2        4          2        2         0            1
  2    3    36        9          4        5          8        6         2            3
  2    4    96        16         6        5          16       16        0            8
  2    5    200       25         8        5          36       30        6            10
  2    6    360       36         10       5          54       54        0            13
  2    7    588       49         12       5          96       84        12           21
  3    2    24        8          3        6          4        4         0            4
  3    3    162       27         6        7          26       22        4            10
  3    4    576       64         9        7          64       64        0            32
\end{filecontents}

\begin{document}
\begin{tikzpicture}
\begin{axis}
\addplot [only marks] table [x=bwgstar, y=servers, discard if not={n}{2}] {data.dat};
\end{axis}
\end{tikzpicture}
\end{document}
  • 1
    I'm just applying this solution now. It is absolutely perfect and efficient. Thank you! – Alejandro Sep 24 '14 at 21:53

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.