tikzpicture に多数の .csv ファイルを追加するには、for ループを追加する必要があります。

tikzpicture に多数の .csv ファイルを追加するには、for ループを追加する必要があります。

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

.csv ファイルからデータをプロットしようとしています。.csv ファイルが多数あります (約 4000 個)。この方法がわかりません。これを実行するための何らかの「for ループ」を探しています。助けていただければ幸いです。以下にサンプル コードを添付しました。

データ ファイルが多数あり、すべての .csv ファイルに 1 行のコードを追加したくありません。これで私の問題が説明されることを願っています。

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

ファイル名が規則的に連続するファイルのコレクションの場合、コマンド\foreachpgfforのユーティリティパッケージである のパッケージから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}

関連情報