
我正在嘗試繪製 .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}