pgfplots:让绘图继续,直到扩大极限

pgfplots:让绘图继续,直到扩大极限

我希望情节一直延续到扩大的极限,而轴刻度不移动。有什么想法吗?

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.14}
\pgfmathdeclarefunction{gauss}{2}{%
    \pgfmathparse{1/(#2*sqrt(2*pi))*exp(-((x-#1)^2)/(2*#2^2))}%
}
\begin{document}
    \begin{figure}[ht]
    \begin{center}
        \begin{tikzpicture}
        \begin{axis}[
        every axis plot post/.append style={
            mark=none,domain=-4:4,samples=100,smooth},
        xtick={-4,-3,...,4},
        grid=both,
        axis x line=bottom,
        axis y line=left,
        enlargelimits=upper]
        \addplot[black!100]{gauss(2,0.75)} node[pos=0.87] (h1) {};
        \node [right,black] at (h1) {$h_1$};            
        \path[] (axis cs:0,0) -- (axis cs:4,0);
        \end{axis}
        \end{tikzpicture}
    \end{center}
    \end{figure}
\end{document}

谢谢你!

答案1

删除该选项enlargelimits,否则当你增加域时它将继续增加画布的大小

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.14}
\pgfmathdeclarefunction{gauss}{2}{%
    \pgfmathparse{1/(#2*sqrt(2*pi))*exp(-((x-#1)^2)/(2*#2^2))}%
}
\begin{document}
    \begin{figure}[ht]
    \begin{center}
        \begin{tikzpicture}
        \begin{axis}[
        every axis plot post/.append style={
            mark=none,domain=-4:4.9,samples=100,smooth},
        xtick={-4,-3,...,4},
        grid=both,
        axis x line=bottom,
        axis y line=left,
        ]
        \addplot[black!100]{gauss(2,0.75)} node[pos=0.87] (h1) {};
        \node [right,black] at (h1) {$h_1$};
        \path[] (axis cs:0,0) -- (axis cs:4,0);
        \end{axis}
        \end{tikzpicture}
    \end{center}
    \end{figure}
\end{document}

在此处输入图片描述

相关内容