Filtering/Indexing 一个以分号分隔的带有浮点数的 csv 文件
Filtering/Indexing a semicolon sepeated csv file with floating point numbers
我想按两个标准过滤和绘制我的数据。
首先,我想按 Test 列过滤数据,然后按 Test No. 过滤数据,然后绘制它。
不幸的是,我在过滤方面一无所获。
我直接用包 pgfplots 试了一下。之后我尝试了包 pgfplotstable,但在这里我也失败了。
以下帖子对我没有帮助:
我的结果:
\documentclass[a4paper,12pt,headsepline]{scrartcl}
\usepackage{tikz,pgfplots,siunitx,pgfplotstable}
\usepgfplotslibrary{units}
\pgfplotsset{compat=1.18}
\usepackage{filecontents}
%\begin{filecontents}{data.csv}
%Test No.;Test;time [s];u [ms]
%A1;A;3;0.045
%A2;A;5;0.06
%A2;A;4;0.05
%A2;A;3;0.04
%A2;A;2;0.03
%A2;A;1;0.02
%A2;A;0;0.01
%A3;A;3;0.044
%B1;B;10;0.045
%B1;B;20;0.06
%B1;B;30;0.05
%B1;B;40;0.04
%B1;B;50;0.03
%B1b;B;10;0.02
%B1b;B;20;0.01
%B1b;B;30;0.044
%B1b;B;40;0.045
%B1b;B;50;0.06
%C1;C;10;0.05
%C1;C;20;0.04
%C1;C;30;0.03
%C1;C;40;0.02
%C1;C;50;0.01
%C1;C;60;0.044
%C1;C;70;0.8
%C2;C;60;0.4
%\end{filecontents}
\begin{document}
\begin{tikzpicture}
\begin{axis}
[
width=\linewidth,
grid=major,
grid style={dashed,gray!30},
xlabel=$time$,
ylabel=$u$,
x unit=\si{\second},
y unit=\si{\meter\per\second}
]
\addplot table [x={time [s]}, y={u [ms]}, col sep=semicolon] {data.csv};
\end{axis}
\end{tikzpicture}
\end{document}
我的解决方案
谢谢@samcarter_is_at_topanswers.xyz 的回答。如果 s/o 想在一张图中绘制更多图表,我刚刚更新了绘图并添加了一些曲线。
\documentclass[a4paper,12pt,headsepline]{scrartcl}
\usepackage{tikz,pgfplots,siunitx,pgfplotstable}
\usepgfplotslibrary{units}
\pgfplotsset{compat=1.18}
\usepackage{filecontents}
\begin{filecontents}{data.csv}
Test No.;Test;time [s];u [ms]
A1;A;3;0.045
A2;A;5;0.06
A2;A;4;0.05
A2;A;3;0.04
A2;A;2;0.03
A2;A;1;0.02
A2;A;0;0.01
A3;A;3;0.044
B1;B;10;0.045
B1;B;20;0.06
B1;B;30;0.05
B1;B;40;0.04
B1;B;50;0.03
B1b;B;10;0.02
B1b;B;20;0.01
B1b;B;30;0.044
B1b;B;40;0.045
B1b;B;50;0.06
C1;C;10;0.05
C1;C;20;0.04
C1;C;30;0.03
C1;C;40;0.02
C1;C;50;0.01
C1;C;60;0.044
C1;C;70;0.8
C2;C;60;0.4
\end{filecontents}
\usepackage{xcolor}
\usepackage{xstring}
\begin{document}
\begin{tikzpicture}
\begin{axis}
[
width=\linewidth,
grid=major,
grid style={dashed,gray!30},
xlabel=$time$,
ylabel=$u$,
x unit=\si{\second},
y unit=\si{\meter\per\second},
]
\addplot [color=blue,
mark=o,
x filter/.code={
\IfStrEq{\thisrow{Test}}{C}{
\IfStrEq{\thisrow{Test No.}}{C1}{}{\def\pgfmathresult{}}
}{\def\pgfmathresult{}}
}, ] table [x={time [s]}, y={u [ms]}, col sep=semicolon] {data.csv};
\addplot [color=red,
mark=*,
x filter/.code={
\IfStrEq{\thisrow{Test}}{B}{
\IfStrEq{\thisrow{Test No.}}{B1b}{}{\def\pgfmathresult{}}
}{\def\pgfmathresult{}}
}, ] table [x={time [s]}, y={u [ms]}, col sep=semicolon] {data.csv};
\addplot [color=green,
mark=x,
x filter/.code={
\IfStrEq{\thisrow{Test}}{A}{
\IfStrEq{\thisrow{Test No.}}{A2}{}{\def\pgfmathresult{}}
}{\def\pgfmathresult{}}
}, ] table [x={time [s]}, y={u [ms]}, col sep=semicolon] {data.csv};
\end{axis}
\end{tikzpicture}
\end{document}
您没有说明要过滤什么,但这里有一个示例,首先检查 Test
是否等于 C
,然后 Test No.
是否为 C1
:
\documentclass[a4paper,12pt,headsepline]{scrartcl}
\usepackage{tikz,pgfplots,siunitx,pgfplotstable}
\usepgfplotslibrary{units}
\pgfplotsset{compat=1.18}
\usepackage{filecontents}
\begin{filecontents}{data.csv}
Test No.;Test;time [s];u [ms]
A1;A;3;0.045
A2;A;5;0.06
A2;A;4;0.05
A2;A;3;0.04
A2;A;2;0.03
A2;A;1;0.02
A2;A;0;0.01
A3;A;3;0.044
B1;B;10;0.045
B1;B;20;0.06
B1;B;30;0.05
B1;B;40;0.04
B1;B;50;0.03
B1b;B;10;0.02
B1b;B;20;0.01
B1b;B;30;0.044
B1b;B;40;0.045
B1b;B;50;0.06
C1;C;10;0.05
C1;C;20;0.04
C1;C;30;0.03
C1;C;40;0.02
C1;C;50;0.01
C1;C;60;0.044
C1;C;70;0.8
C2;C;60;0.4
\end{filecontents}
\usepackage{xstring}
\begin{document}
\begin{tikzpicture}
\begin{axis}
[
width=\linewidth,
grid=major,
grid style={dashed,gray!30},
xlabel=$time$,
ylabel=$u$,
x unit=\si{\second},
y unit=\si{\meter\per\second},
x filter/.code={
\IfStrEq{\thisrow{Test}}{C}{
\IfStrEq{\thisrow{Test No.}}{C1}{}{\def\pgfmathresult{}}
}{\def\pgfmathresult{}}
},
]
\addplot table [x={time [s]}, y={u [ms]}, col sep=semicolon] {data.csv};
\end{axis}
\end{tikzpicture}
\end{document}
我想按两个标准过滤和绘制我的数据。 首先,我想按 Test 列过滤数据,然后按 Test No. 过滤数据,然后绘制它。 不幸的是,我在过滤方面一无所获。 我直接用包 pgfplots 试了一下。之后我尝试了包 pgfplotstable,但在这里我也失败了。
以下帖子对我没有帮助:
我的结果:
\documentclass[a4paper,12pt,headsepline]{scrartcl}
\usepackage{tikz,pgfplots,siunitx,pgfplotstable}
\usepgfplotslibrary{units}
\pgfplotsset{compat=1.18}
\usepackage{filecontents}
%\begin{filecontents}{data.csv}
%Test No.;Test;time [s];u [ms]
%A1;A;3;0.045
%A2;A;5;0.06
%A2;A;4;0.05
%A2;A;3;0.04
%A2;A;2;0.03
%A2;A;1;0.02
%A2;A;0;0.01
%A3;A;3;0.044
%B1;B;10;0.045
%B1;B;20;0.06
%B1;B;30;0.05
%B1;B;40;0.04
%B1;B;50;0.03
%B1b;B;10;0.02
%B1b;B;20;0.01
%B1b;B;30;0.044
%B1b;B;40;0.045
%B1b;B;50;0.06
%C1;C;10;0.05
%C1;C;20;0.04
%C1;C;30;0.03
%C1;C;40;0.02
%C1;C;50;0.01
%C1;C;60;0.044
%C1;C;70;0.8
%C2;C;60;0.4
%\end{filecontents}
\begin{document}
\begin{tikzpicture}
\begin{axis}
[
width=\linewidth,
grid=major,
grid style={dashed,gray!30},
xlabel=$time$,
ylabel=$u$,
x unit=\si{\second},
y unit=\si{\meter\per\second}
]
\addplot table [x={time [s]}, y={u [ms]}, col sep=semicolon] {data.csv};
\end{axis}
\end{tikzpicture}
\end{document}
我的解决方案
谢谢@samcarter_is_at_topanswers.xyz 的回答。如果 s/o 想在一张图中绘制更多图表,我刚刚更新了绘图并添加了一些曲线。
\documentclass[a4paper,12pt,headsepline]{scrartcl}
\usepackage{tikz,pgfplots,siunitx,pgfplotstable}
\usepgfplotslibrary{units}
\pgfplotsset{compat=1.18}
\usepackage{filecontents}
\begin{filecontents}{data.csv}
Test No.;Test;time [s];u [ms]
A1;A;3;0.045
A2;A;5;0.06
A2;A;4;0.05
A2;A;3;0.04
A2;A;2;0.03
A2;A;1;0.02
A2;A;0;0.01
A3;A;3;0.044
B1;B;10;0.045
B1;B;20;0.06
B1;B;30;0.05
B1;B;40;0.04
B1;B;50;0.03
B1b;B;10;0.02
B1b;B;20;0.01
B1b;B;30;0.044
B1b;B;40;0.045
B1b;B;50;0.06
C1;C;10;0.05
C1;C;20;0.04
C1;C;30;0.03
C1;C;40;0.02
C1;C;50;0.01
C1;C;60;0.044
C1;C;70;0.8
C2;C;60;0.4
\end{filecontents}
\usepackage{xcolor}
\usepackage{xstring}
\begin{document}
\begin{tikzpicture}
\begin{axis}
[
width=\linewidth,
grid=major,
grid style={dashed,gray!30},
xlabel=$time$,
ylabel=$u$,
x unit=\si{\second},
y unit=\si{\meter\per\second},
]
\addplot [color=blue,
mark=o,
x filter/.code={
\IfStrEq{\thisrow{Test}}{C}{
\IfStrEq{\thisrow{Test No.}}{C1}{}{\def\pgfmathresult{}}
}{\def\pgfmathresult{}}
}, ] table [x={time [s]}, y={u [ms]}, col sep=semicolon] {data.csv};
\addplot [color=red,
mark=*,
x filter/.code={
\IfStrEq{\thisrow{Test}}{B}{
\IfStrEq{\thisrow{Test No.}}{B1b}{}{\def\pgfmathresult{}}
}{\def\pgfmathresult{}}
}, ] table [x={time [s]}, y={u [ms]}, col sep=semicolon] {data.csv};
\addplot [color=green,
mark=x,
x filter/.code={
\IfStrEq{\thisrow{Test}}{A}{
\IfStrEq{\thisrow{Test No.}}{A2}{}{\def\pgfmathresult{}}
}{\def\pgfmathresult{}}
}, ] table [x={time [s]}, y={u [ms]}, col sep=semicolon] {data.csv};
\end{axis}
\end{tikzpicture}
\end{document}
您没有说明要过滤什么,但这里有一个示例,首先检查 Test
是否等于 C
,然后 Test No.
是否为 C1
:
\documentclass[a4paper,12pt,headsepline]{scrartcl}
\usepackage{tikz,pgfplots,siunitx,pgfplotstable}
\usepgfplotslibrary{units}
\pgfplotsset{compat=1.18}
\usepackage{filecontents}
\begin{filecontents}{data.csv}
Test No.;Test;time [s];u [ms]
A1;A;3;0.045
A2;A;5;0.06
A2;A;4;0.05
A2;A;3;0.04
A2;A;2;0.03
A2;A;1;0.02
A2;A;0;0.01
A3;A;3;0.044
B1;B;10;0.045
B1;B;20;0.06
B1;B;30;0.05
B1;B;40;0.04
B1;B;50;0.03
B1b;B;10;0.02
B1b;B;20;0.01
B1b;B;30;0.044
B1b;B;40;0.045
B1b;B;50;0.06
C1;C;10;0.05
C1;C;20;0.04
C1;C;30;0.03
C1;C;40;0.02
C1;C;50;0.01
C1;C;60;0.044
C1;C;70;0.8
C2;C;60;0.4
\end{filecontents}
\usepackage{xstring}
\begin{document}
\begin{tikzpicture}
\begin{axis}
[
width=\linewidth,
grid=major,
grid style={dashed,gray!30},
xlabel=$time$,
ylabel=$u$,
x unit=\si{\second},
y unit=\si{\meter\per\second},
x filter/.code={
\IfStrEq{\thisrow{Test}}{C}{
\IfStrEq{\thisrow{Test No.}}{C1}{}{\def\pgfmathresult{}}
}{\def\pgfmathresult{}}
},
]
\addplot table [x={time [s]}, y={u [ms]}, col sep=semicolon] {data.csv};
\end{axis}
\end{tikzpicture}
\end{document}