
Estou tentando definir a quantidade de amostras por tikzpicture globalmente:
\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}
Não consegui fazer isso funcionar com contadores primitivos TeX, \value
, \def
, \let
, \newcommand
, etc.
Responder1
Você pode usar \newcommand
para isso, por exemplo
\newcommand\samplesize{100}
Observe também que, por padrão, a standalone
classe não parece lidar com títulos de seção (entre outras coisas), mas se você adicioná varwidth=true
-la, funcionará. (Embora \section
talvez fosse apenas uma relíquia de um documento completo.)
Código completo:
\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}