如果元列符合條件,則使用 pgfplots 繪製數據

如果元列符合條件,則使用 pgfplots 繪製數據

我有一個包含許多列的資料文件,我想繪製 n=2 時 bwgstar 與伺服器的關係圖。所以 n 是元列,伺服器在 x 軸上,bwgstar 在 y 軸上。我想在乳膠文件中執行此操作,以便稍後可以重新生成數據。

下面顯示了一些數據的簡短版本。

  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

答案1

您可以調整該方法過濾表中的行

\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}

相關內容