pgfplotstable: gnuplot에서 생성된 테이블을 읽고 조판합니다.

pgfplotstable: gnuplot에서 생성된 테이블을 읽고 조판합니다.

나는 처음이다pgfplotstable, 나는 읽으려고 노력하고 있어요gnuplot으로 테이블을 내보냈습니다 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

질문

pgfplotstableby 에서 사용자 정의 형식 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}두 열의 전체 gnuplot테이블을 읽고file.datselect equal part entry of두 개의 열을 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}

관련 정보