我正在尝试全局设置每个 tikzpicture 的样本数量:
\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}
我无法让它与 TeX 原始计数器、、、、、等\value
一起工作。\def
\let
\newcommand
答案1
你可以使用\newcommand
这个,例如
\newcommand\samplesize{100}
还要注意,默认情况下,该类standalone
似乎不处理节标题(以及其他内容),但如果您添加varwidth=true
它,它将起作用。(尽管这\section
可能只是完整文档的遗留。)
完整代码:
\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}