
Ich habe den folgenden Code erstellt, der anscheinend das tut, was ich möchte. Nämlich der Tabelle eine zusätzliche Zeile hinzufügen, \IDA
die den Durchschnitt von vier Werten darstellt. Diese Zeile kann dann für ein Diagramm in verwendet werden tikzpicture
.
\documentclass[tikz]{standalone}
\usepackage{filecontents}
\usepackage{pgfplots, pgfplotstable}
\begin{filecontents}{FileA.dat}
step ts1 ts2
1 3 4
2 7 6
3 4 6
4 5 6
5 5 7
6 9 3
\end{filecontents}
\begin{filecontents}{FileB.dat}
step tHIws
1 3
2 7
3 4
4 5
5 5
6 9
\end{filecontents}
% for calculations
\pgfplotstableread{FileB.dat}\SST
\pgfplotstableread{FileA.dat}\IDA
\pgfplotstableset{
create on use/tHIws/.style={
create col/expr={\thisrow{ts1}+\thisrow{ts2})/2}
}
}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis x line=bottom,
axis y line=left,
tick align=outside,
xlabel=\texttt{step},
ylabel={$\theta_{a}$},
legend pos= north west,
legend columns=6,
legend style={fill=none, draw=none},
cycle multi list={
color list%
},
ymajorgrids,
]
\addplot table
[x=step, y=tHIws]
{\SST};
\addlegendentry{SSTe}
\addplot +[mark=*] table
[x=step, y=tHIws]
{\IDA};
\addlegendentry{IDA}
\addplot table
[x=step, y expr=(\thisrow{ts1}+\thisrow{ts2})/2]
{FileA.dat};
\addlegendentry{IDA}
\end{axis}
\end{tikzpicture}
\end{document}
Da ich dies jedoch für mehrere Tabellen/Abbildungen tun muss, möchte ich die beiden Befehle irgendwie zu einem kombinieren oder zumindest sicherstellen, dass das Obige \pgfplotstableset
nur auf die Tabelle angewendet wird \IDA
.
Gibt es eine Möglichkeit, dies zu tun?
Aufgrund der Antwort von percusse bearbeitet. Ich habe tatsächlich versucht, das auf tikxpictures zu übertragen, aber bisher ist es nicht gelungen.
Bearbeitung 2: Vollständiges Beispiel!
Edit 3: Jetzt mit internen Daten. Allerdings bekomme ich beim Kompilieren eine Fehlermeldung: "Spalte 'step' konnte nicht aus Tabelle 'FileA.dat' abgerufen werden." Aber ich kann den Fehler nicht erkennen - ich bin wohl "betriebsblind"
Edit 4: Fehlendes Usepackage für den Inline-Dateiinhalt hinzugefügt
Antwort1
Was die Bearbeitung betrifft, ist es einfacher, den Ausdruck in einen Stil einzufügen und ihn bei Bedarf anzuwenden. Hier habe ich es genanntmymedian
\documentclass{standalone}
\usepackage{pgfplotstable}
\pgfplotsset{compat=1.10}
\pgfplotstableread{
step ts1 ts2 ts3 ts4
1 3 4 11 14
2 7 6 22 26
3 4 6 34 31
4 5 6 45 46
5 5 7 55 57
6 9 3 69 63
}\SST
% for calculations
\pgfplotsset{mymedian/.style={
x=step, y expr=(\thisrow{ts1}+\thisrow{ts2}+\thisrow{ts3}+\thisrow{ts4})/4
}
}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis x line=bottom,
axis y line=left,
tick align=outside,
xlabel=\texttt{step},
ylabel={$\theta_{a}$},
legend pos= north west,
legend columns=6,
legend style={fill=none, draw=none},
cycle multi list={
color list%
},
ymajorgrids,
]
\addplot table[mymedian] {\SST};
\addlegendentry{SSTmean}
\addplot table[x=step,y=ts3] {\SST};
\addlegendentry{SSTS3}
\end{axis}
\end{tikzpicture}
\end{document}