Seite 1 von 1

pgfplots foreach und notes

Verfasst: Do 20. Apr 2017, 11:03
von jensjj
Guten Morgen liebe LaTeX-Experten,
ich bin hier neu, habe zwar schon einige gute Hinweise und Tipps gefunden und besitze aber eher Anfängerkentnisse.

Ich erstelle in der tikzpicture-Umgebung ein Diagramm mit neun Funktionsplotts, wobei sich immer nur eine Variable ändert. Das löse ich über eine \foreach-Schleife. Funktioniert auch ohne Probleme.
Hier kommt mein Problem: Ich möchte für jede der neun Plots über eine "note" die veränderliche Variable an dan den jeweiligen Plot schreiben. Mit der Variablen (\trenngrad) als Argument in der note bekomme ich nur das Alpha und das Gleichheitszeichen angezeigt und die Meldung: "Undefined control sequence. \end{axis}". Mit einer Konstanten anstatt \trenngrad läuft es ohne Fehler durch. Muss ich das irgentwie maskieren oder fehlt mir ein Paket? Über Hinweise, was ich falsch mache, würde ich mich sehr freuen.

Hier mein Code:
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{height=9cm,width=9cm,compat=1.5}
\begin{document}	
\begin{tikzpicture}
	\pgfplotsset{
		every axis plot post/.append style={
			domain=0:1,
			samples=101
			}
		}
	\begin{axis}[
		xlabel={$x$},
		ylabel={$y$},
		grid=major,
		xmin=0, xmax=1,
		ymin=0, ymax=1
		]
	\foreach \trennfaktor in {0.01, 0.04, 0.125, 0.333, 1, 3, 8, 25, 100}{
		\addplot[]{\trennfaktor*x/(1-x+\trennfaktor*x)}node[pos=0.5,yshift=5pt,sloped]{$\alpha=$\trennfaktor};
	}
	\end{axis}
\end{tikzpicture}
\end{document}

Verfasst: Do 20. Apr 2017, 12:06
von esdd
Nimm \pgfplotsforeachungrouped:
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{height=9cm,width=9cm,compat=1.5}
\begin{document}   
\begin{tikzpicture}
   \pgfplotsset{
      every axis plot post/.append style={
         domain=0:1,
         samples=101
         }
      }
   \begin{axis}[
      xlabel={$x$},
      ylabel={$y$},
      grid=major,
      xmin=0, xmax=1,
      ymin=0, ymax=1
      ]
   \pgfplotsforeachungrouped \trennfaktor in {0.01, 0.04, 0.125, 0.333, 1, 3, 8, 25, 100}{
      \addplot[]{\trennfaktor*x/(1-x+\trennfaktor*x)}node[pos=0.5,yshift=5pt,sloped]{$\alpha=$\trennfaktor};
   }
   \end{axis}
\end{tikzpicture}
\end{document}


Alternativ geht auch \pgfplotsinvokeforeach:
   \pgfplotsinvokeforeach{0.01, 0.04, 0.125, 0.333, 1, 3, 8, 25, 100}{
      \addplot[]{#1*x/(1-x+#1*x)}node[pos=0.5,yshift=5pt,sloped]{$\alpha=$#1};
   }
Du hast compat=1.5 eingestellt. Möchtest/Brauchst Du tatsächlich Kompatibilität zu so einer alten Version? Aktuell ist derzeit 1.14.

Verfasst: Do 20. Apr 2017, 12:11
von jensjj
Oh, dass ging ja schnell! Vielen Dank, läuft jetzt.
Das mit der Version kannst Du meiner Unwissenheit zuschreiben. Habe ich auch geändert.