tikzpicture에 많은 .csv 파일을 추가하려면 for 루프를 추가해야 합니다.

tikzpicture에 많은 .csv 파일을 추가하려면 for 루프를 추가해야 합니다.

여기에 이미지 설명을 입력하세요

.csv 파일의 데이터를 플롯하려고 합니다. .csv 파일이 많이 있습니다(약 4000개). 이 작업을 수행하는 방법을 잘 모르겠습니다. 나는 이것을 수행하기 위해 일종의 "for 루프"를 찾고 있습니다. 어떤 도움이라도 주시면 감사하겠습니다. 아래에 예제 코드를 첨부했습니다.

데이터 파일이 너무 많아서 모든 .csv 파일에 대해 한 줄의 코드를 추가하고 싶지 않습니다. 이것이 내 문제를 설명하기를 바랍니다.

%\title{Plot_for_gain_tuning_paper}
\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{filecontents}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{4pt}
\pgfplotsset{width=9.75cm,compat=1.3} 
\pgfplotsset{every axis legend/.append style={at={(0.45,-0.25)},legend columns=5,anchor=south,font=\small}}
\tikzset{every mark/.append style={scale=0.8}}
\pgfplotsset{compat=1.8}
\begin{document}

\begin{tikzpicture}
\begin{axis}[title=$V_{a_{rms}}+V_{b_{rms}}+V_{c_{rms}}$,xlabel={Time (in seconds)},ylabel={Voltage (in Volts)},grid=major,legend entries={$Index~1$,$Index~2$,$Index~3$,$Index~4$,$Index~5$}]
\addplot[color=black,style=solid,very thick] table [col sep=comma] {Data_128_4_1.csv};
\addplot[color=black,style=solid,very thick] table [col sep=comma] {Data_128_4_2.csv};
\addplot[color=black,style=solid,very thick] table [col sep=comma] {Data_128_4_3.csv};
\addplot[color=black,style=solid,very thick] table [col sep=comma] {Data_128_4_4.csv};
\end{axis}
\end{tikzpicture}
\end{document}

답변1

파일 이름이 정기적으로 '진행'되는 파일 모음의 경우 명령 \foreach(패키지의 pgffor유틸리티 패키지 tikz)이 도움이 될 수 있습니다. 대신에

\begin{tikzpicture}
\begin{axis}[title=$V_{a_{rms}}+V_{b_{rms}}+V_{c_{rms}}$,xlabel={Time (in seconds)},ylabel={Voltage (in Volts)},grid=major,legend entries={$Index~1$,$Index~2$,$Index~3$,$Index~4$,$Index~5$}]
\addplot[color=black,style=solid,very thick] table [col sep=comma] {Data_128_4_1.csv};
\addplot[color=black,style=solid,very thick] table [col sep=comma] {Data_128_4_2.csv};
\addplot[color=black,style=solid,very thick] table [col sep=comma] {Data_128_4_3.csv};
...
\addplot[color=black,style=solid,very thick] table [col sep=comma] {Data_128_4_1000.csv};
\end{axis}
\end{tikzpicture}

당신은 가질 수 있습니다 :

\begin{tikzpicture}
\begin{axis}[
        title=$V_{a_{rms}}+V_{b_{rms}}+V_{c_{rms}}$,
        xlabel={Time (in seconds)},
        ylabel={Voltage (in Volts)},
        grid=major,
        legend entries={$Index~1$,$Index~2$,$Index~3$,$Index~4$,$Index~5$}
    ]

    \foreach \F in {1,2,...,1000}{
            \addplot[
                color=black,
                style=solid,
                very thick
            ] table [col sep=comma] {Data_128_4_\F.csv};
        }

\end{axis}
\end{tikzpicture}

관련 정보