von Noch so einer » Do 24. Mär 2016, 08:03
Und hier mal noch gezeigt, wie das mit mehreren Messreihen in einer Datei geht, bei denen sich die Messwerte alle auf dieselben Zeitpunkte beziehen:
\documentclass[paper=landscape,DIV=40]{scrartcl}
\usepackage{datatool,longtable}
\usepackage{pgfplots}
\pgfplotsset{compat=1.13}
\usepgfplotslibrary{dateplot}
\pgfplotsset{/pgf/number format/use comma,
/pgf/number format/read comma as period}
\usepackage{filecontents}
\begin{filecontents*}{\jobname.dat}
Dauer Kraft Weg
00:00:01 21,490365 12,0
00:00:17 21,4798313333 12,04
00:00:34 21,4662983333 12,06
00:00:52 21,4617970000 12,10
00:01:09 21,4557646667 12,11
00:01:26 21,4482323333 12,15
00:01:44 21,4407003333 12,19
\end{filecontents*}
\newcommand*{\mysep}{ }
\DTLsetseparator{ }
\DTLloaddb[noheader,keys={Dauer,Kraft,Weg},omitlines=1]{dauerkraft}{\jobname.dat}
\newwrite\plotfile
\immediate\openout\plotfile \jobname.csv
\immediate\write\plotfile{Sekunden\mysep Dauer\mysep Kraft\mysep Weg}
\newcommand*\SECONDSOF{}
\def\SECONDSOF#1:#2:#3:{\the\numexpr 3600*#1+60*#2+#3\relax}
\DTLforeach[\NOT\equal{\Dauer}{\csname @dtlstringnull\endcsname}]{dauerkraft}{\Dauer=Dauer,\Kraft=Kraft,\Weg=Weg}{%
\immediate\write\plotfile{\expandafter\SECONDSOF\Dauer:\mysep\Dauer\mysep\Kraft\mysep\Weg}%
}
\immediate\closeout\plotfile
\pgfplotstableread{\jobname.csv}\sekundendauerkrafttable
\begin{document}
\begin{tikzpicture}
\begin{axis}[%
height=\textheight,
width=\textwidth,
xtick={0,30,...,120},
% x tick label style={rotate=90,anchor=east},
xticklabel={\pgfkeys{/pgf/number format/.cd,fixed,precision=0}%
\pgfmathsetmacro\hours{floor(\tick/3600)}%
\pgfmathsetmacro\minutes{floor(\tick/60)-\hours*60}%
\pgfmathsetmacro\seconds{\tick-\minutes*60-\hours*3600}%
\pgfmathparse{ifthenelse(\hours<10,0,)}\pgfmathresult\pgfmathprintnumber{\hours}:%
\pgfmathparse{ifthenelse(\minutes<10,0,)}\pgfmathresult\pgfmathprintnumber{\minutes}:%
\pgfmathparse{ifthenelse(\seconds<10,0,)}\pgfmathresult\pgfmathprintnumber{\seconds}}
]%
\addplot table[x=Sekunden,y=Kraft] {\sekundendauerkrafttable};% für y die Kraft-Spalte verwenden
\end{axis}
\end{tikzpicture}
\begin{tikzpicture}
\begin{axis}[%
height=\textheight,
width=\textwidth,
xtick={0,30,...,120},
% x tick label style={rotate=90,anchor=east},
xticklabel={\pgfkeys{/pgf/number format/.cd,fixed,precision=0}%
\pgfmathsetmacro\hours{floor(\tick/3600)}%
\pgfmathsetmacro\minutes{floor(\tick/60)-\hours*60}%
\pgfmathsetmacro\seconds{\tick-\minutes*60-\hours*3600}%
\pgfmathparse{ifthenelse(\hours<10,0,)}\pgfmathresult\pgfmathprintnumber{\hours}:%
\pgfmathparse{ifthenelse(\minutes<10,0,)}\pgfmathresult\pgfmathprintnumber{\minutes}:%
\pgfmathparse{ifthenelse(\seconds<10,0,)}\pgfmathresult\pgfmathprintnumber{\seconds}}
]%
\addplot table[x=Sekunden,y=Weg] {\sekundendauerkrafttable};% für y die Weg-Spalte verwenden
\end{axis}
\end{tikzpicture}
\end{document}
Die beiden Diagramme unterscheiden sich lediglich in der Auswahl der y-Spalte bei \addplot table.
Und hier mal noch gezeigt, wie das mit mehreren Messreihen in einer Datei geht, bei denen sich die Messwerte alle auf dieselben Zeitpunkte beziehen: [code]\documentclass[paper=landscape,DIV=40]{scrartcl}
\usepackage{datatool,longtable}
\usepackage{pgfplots}
\pgfplotsset{compat=1.13}
\usepgfplotslibrary{dateplot}
\pgfplotsset{/pgf/number format/use comma,
/pgf/number format/read comma as period}
\usepackage{filecontents}
\begin{filecontents*}{\jobname.dat}
Dauer Kraft Weg
00:00:01 21,490365 12,0
00:00:17 21,4798313333 12,04
00:00:34 21,4662983333 12,06
00:00:52 21,4617970000 12,10
00:01:09 21,4557646667 12,11
00:01:26 21,4482323333 12,15
00:01:44 21,4407003333 12,19
\end{filecontents*}
\newcommand*{\mysep}{ }
\DTLsetseparator{ }
\DTLloaddb[noheader,keys={Dauer,Kraft,Weg},omitlines=1]{dauerkraft}{\jobname.dat}
\newwrite\plotfile
\immediate\openout\plotfile \jobname.csv
\immediate\write\plotfile{Sekunden\mysep Dauer\mysep Kraft\mysep Weg}
\newcommand*\SECONDSOF{}
\def\SECONDSOF#1:#2:#3:{\the\numexpr 3600*#1+60*#2+#3\relax}
\DTLforeach[\NOT\equal{\Dauer}{\csname @dtlstringnull\endcsname}]{dauerkraft}{\Dauer=Dauer,\Kraft=Kraft,\Weg=Weg}{%
\immediate\write\plotfile{\expandafter\SECONDSOF\Dauer:\mysep\Dauer\mysep\Kraft\mysep\Weg}%
}
\immediate\closeout\plotfile
\pgfplotstableread{\jobname.csv}\sekundendauerkrafttable
\begin{document}
\begin{tikzpicture}
\begin{axis}[%
height=\textheight,
width=\textwidth,
xtick={0,30,...,120},
% x tick label style={rotate=90,anchor=east},
xticklabel={\pgfkeys{/pgf/number format/.cd,fixed,precision=0}%
\pgfmathsetmacro\hours{floor(\tick/3600)}%
\pgfmathsetmacro\minutes{floor(\tick/60)-\hours*60}%
\pgfmathsetmacro\seconds{\tick-\minutes*60-\hours*3600}%
\pgfmathparse{ifthenelse(\hours<10,0,)}\pgfmathresult\pgfmathprintnumber{\hours}:%
\pgfmathparse{ifthenelse(\minutes<10,0,)}\pgfmathresult\pgfmathprintnumber{\minutes}:%
\pgfmathparse{ifthenelse(\seconds<10,0,)}\pgfmathresult\pgfmathprintnumber{\seconds}}
]%
\addplot table[x=Sekunden,y=Kraft] {\sekundendauerkrafttable};% für y die Kraft-Spalte verwenden
\end{axis}
\end{tikzpicture}
\begin{tikzpicture}
\begin{axis}[%
height=\textheight,
width=\textwidth,
xtick={0,30,...,120},
% x tick label style={rotate=90,anchor=east},
xticklabel={\pgfkeys{/pgf/number format/.cd,fixed,precision=0}%
\pgfmathsetmacro\hours{floor(\tick/3600)}%
\pgfmathsetmacro\minutes{floor(\tick/60)-\hours*60}%
\pgfmathsetmacro\seconds{\tick-\minutes*60-\hours*3600}%
\pgfmathparse{ifthenelse(\hours<10,0,)}\pgfmathresult\pgfmathprintnumber{\hours}:%
\pgfmathparse{ifthenelse(\minutes<10,0,)}\pgfmathresult\pgfmathprintnumber{\minutes}:%
\pgfmathparse{ifthenelse(\seconds<10,0,)}\pgfmathresult\pgfmathprintnumber{\seconds}}
]%
\addplot table[x=Sekunden,y=Weg] {\sekundendauerkrafttable};% für y die Weg-Spalte verwenden
\end{axis}
\end{tikzpicture}
\end{document}[/code]
Die beiden Diagramme unterscheiden sich lediglich in der Auswahl der y-Spalte bei [tt]\addplot table[/tt].