
Ich versuche, die Anzahl der Samples pro Tikz-Bild global festzulegen:
\documentclass{standalone}
\usepackage{pgfplots}
\pgfmathdeclarefunction{gauss}{2}{%
\pgfmathparse{1/(#2*sqrt(2*pi))*exp(-((x-#1)^2)/(2*#2^2))}%
}
%\samplesize = <number>% How do I get this one to work?
\begin{document}
\section{Gaussian distribution}
\begin{tikzpicture}
\begin{axis}[
hide y axis,
axis lines*=center,
axis on top,
no markers,
domain=2.5:25.5,
samples=\samplesize,
xlabel=\empty,
ylabel=\empty,
every axis x label/.style={at=(current axis.right of origin),anchor=west},
every axis y label/.style={at=(current axis.above origin),anchor=south},
height=5cm, width=12cm,
xmin = 4, xmax=24,
xtick={14}, ytick=\empty,
enlargelimits=false,
clip=false,
grid=major
]
\addplot [fill=cyan!20, draw=cyan!80, domain=4:7] {gauss(14,3.41696)} \closedcycle;
\addplot [very thick,cyan!50!black] {gauss(14,3.416969)};
\end{axis}
\end{tikzpicture}
\end{document}
Ich habe es nicht geschafft, dies mit den primitiven Zählern von TeX usw. zum Laufen \value
zu bringen \def
.\let
\newcommand
Antwort1
Sie können \newcommand
hierfür beispielsweise verwenden
\newcommand\samplesize{100}
Beachten Sie auch, dass die Klasse standardmäßig standalone
keine Abschnittsüberschriften (unter anderem) zu verarbeiten scheint, aber wenn Sie varwidth=true
sie hinzufügen, funktioniert sie. (Obwohl dies \section
vielleicht nur ein Relikt aus einem vollständigen Dokument war.)
Vollständiger Code:
\documentclass[varwidth=true]{standalone}
\usepackage{pgfplots}
\pgfmathdeclarefunction{gauss}{2}{%
\pgfmathparse{1/(#2*sqrt(2*pi))*exp(-((x-#1)^2)/(2*#2^2))}%
}
\newcommand\samplesize{100}
\begin{document}
\section{Gaussian distribution}
\begin{tikzpicture}
\begin{axis}[
hide y axis,
axis lines*=center,
axis on top,
no markers,
domain=2.5:25.5,
samples=\samplesize,
xlabel=\empty,
ylabel=\empty,
every axis x label/.style={at=(current axis.right of origin),anchor=west},
every axis y label/.style={at=(current axis.above origin),anchor=south},
height=5cm, width=12cm,
xmin = 4, xmax=24,
xtick={14}, ytick=\empty,
enlargelimits=false,
clip=false,
grid=major
]
\addplot [fill=cyan!20, draw=cyan!80, domain=4:7] {gauss(14,3.41696)} \closedcycle;
\addplot [very thick,cyan!50!black] {gauss(14,3.416969)};
\end{axis}
\end{tikzpicture}
\end{document}