pgfplotstable: gnuplot で生成されたテーブルを読み取り、タイプセットする

pgfplotstable: gnuplot で生成されたテーブルを読み取り、タイプセットする

私は初心者ですpgfplotstable、私は読もうとしているグナプロットにエクスポートされたテーブルpgfplotstable

gnuplot スクリプト:

set samples 91
set table "file.dat"
set angles degrees
plot [0:90] sin(x),cos(x),tan(x);
unset table

gnuplot テーブルfile.datは以下のとおりです (簡潔にするために 5 つのポイントを示します)。

# Curve 0 of 3, 91 points
# Curve title: "sin(x)"
# x y type
 0  0  i
 1  0.0174524  i
 2  0.0348995  i
 3  0.052336  i
 4  0.0697565  i
 5  0.0871557  i

# Curve 1 of 3, 91 points
# Curve title: "cos(x)"
# x y type
 0  1  i
 1  0.999848  i
 2  0.999391  i
 3  0.99863  i
 4  0.997564  i
 5  0.996195  i

# Curve 2 of 3, 91 points
# Curve title: "tan(x)"
# x y type
 0  0  i
 1  0.0174551  i
 2  0.0349208  i
 3  0.0524078  i
 4  0.0699268  i
 5  0.0874887  i

注: 上記の場合 (すべてのデータが順番に並べられている) と比較して、以下に示す表のヘッダーと形式 (すべてのデータが列に並べられている) を読み取ることができます。

# A B C 
  1 2 3 
  4 5 7
  8 9 10

質問

pgfplotstableでカスタム形式の ASCII ファイルを読み込む\pgfplotstableset{}ことや、gnuplot で他の回避策を実行して、適切に読み込んで でタイプセットすることは可能ですかpgfplotstable?

答え1

最初はデータをプロットしたいのだと思っていましたが、質問をもう一度読んでみると、 を使用してデータをテーブルとして設定したいだけのように思えます。 のようpgfplotstableにすることができますが、この場合に本当に役立つかどうかはわかりません。pgfplotstableが読み取れるようにデータを再配置するまでに、\pgfplotstabletypesetとして書き込むだけで済みますlongtable。ただし...

ここに画像の説明を入力してください

[最初の列が整数でない場合の更新]

\documentclass{article}
\usepackage{pgfplotstable,longtable,array}

\begin{document}
\makeatletter

\def\loopb#1\repeatb{\def\iterateb{#1\relax\expandafter\iterateb\fi}%
  \iterateb \let\iterateb\relax}
\let\repeatb\fi

\begingroup

\count@\z@
\catcode`\#12
\catcode`\*=6

\def\tstrelax{\relax}
\def\tsti{i}

\def\ca*1# Curve*2 of *3,*4 points*5!!{%
  \def\cnum{*2}\def\ctot{*3}\def\cpoints{*4}}

\def\cb*1# Curve title: "*2"*3!!{%
  \def\title{*2}}

\def\cc*1 *2 *3 *4!!{%
\def\x{*1}\def\y{*2}\def\ci{*3}}

\newread\myin
\openin\myin=file.dat

\@tempcnta\z@

\loop
\ifeof\myin\else
\read\myin to \tmp
\expandafter\ifx\expandafter\par\tmp
\else
  \expandafter\cb\tmp# Curve title: "\relax"!!%
  \ifx\title\tstrelax
    \expandafter\ca\tmp# Curve of \relax, points!!%
    \ifx\ctot\tstrelax
      \expandafter\cc\tmp. . . !!%
      \ifx\ci\tsti
        \expandafter\edef\csname my-\the\@tempcnta-\the\@tempcntb\endcsname{\ifnum\@tempcnta=1 \x\space\fi\y}
        \advance\@tempcntb\@ne
 \fi
    \else
      \let\total\ctot
      \let\points\cpoints
      \advance\@tempcnta\@ne
      \@tempcntb\z@
    \fi
  \else
    \expandafter\let\csname my-\the\@tempcnta-title\endcsname\title
  \fi
\fi
\repeat

{\let\\\relax

\gdef\mytable{}
\gdef\row{x}
\@tempcnta\z@
\loop
\advance\@tempcnta\@ne
\xdef\row{\row\space \csname my-\the\@tempcnta-title\endcsname}
\ifnum\@tempcnta<\total
\repeat
\xdef\mytable{\row\space\\\space}

\@tempcntb\z@
\loopb
\xdef\row{}
\@tempcnta\z@
\loop
\advance\@tempcnta\@ne
\xdef\row{\row\space \csname my-\the\@tempcnta-\the\@tempcntb\endcsname}
\ifnum\@tempcnta<\total
\repeat
\xdef\mytable{\mytable\row\space\\\space}
\advance\@tempcntb\@ne
\ifnum\@tempcntb<\points
\repeatb

\show\mytable
\xdef\tmp{\noexpand\pgfplotstabletypeset[row sep=\noexpand\\, begin table=\noexpand\begin{longtable}, 
end table=\noexpand\end{longtable}
sci,precision=5]{\mytable}}
}



\endgroup

\tmp

\end{document}

答え2

上記のような低レベルのTeXの回答ではありませんが、以前は驚くほど見落とされていましたが、今日pgfplotstableオプションを使用するとignore chars={\i}2列でgnuplot表全体を読むにはfile.datselect equal part entry of2 つの列を 3 列の均等な行に並べ替えます。ただし、複数のヘッダー ("sin(x)"、"cos(x)"、"tan(x)") を自動的に読み取る pgfplotstable オプションが見つかりませんでした。

ここに画像の説明を入力してください

\documentclass[12pt]{article}
\usepackage{pgfplotstable}
\pgfplotsset{compat=newest}
\usepackage{booktabs}
\usepackage{colortbl}
\usepackage{longtable}
\pgfplotstableset{begin table=\begin{longtable},end table=\end{longtable},%
every head row/.style={before row=\toprule,after row=\midrule},%
every last row/.style={after row=\bottomrule},%
every even row/.style={before row={\rowcolor[gray]{.8}}}%
}
\begin{document}
\pgfplotstabletypeset[columns={0,1,1,1},%
display columns/0/.style={select equal part entry of={0}{3},column name=$x$},%
display columns/1/.style={select equal part entry of={0}{3},column name=$sin(x)$},%
display columns/2/.style={select equal part entry of={1}{3},column name=$cos(x)$},%
display columns/3/.style={select equal part entry of={2}{3},column name=$tan(x)$},%
precision=5,ignore chars={\i}]{file.dat}
\end{document}

関連情報