
我正在嘗試在全域範圍內設定每個 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}