我正在使用 tikz 将漂亮的图形从 Matlab 放入 latex 中。我遇到的问题是,我在 tikz 上写了一个图(一组密度函数的连续点),我有两条垂直线截断了这个分布。正如
我想做的是在这两条垂直线之间添加阴影,并且还想给 x 轴上的那些点添加标签,我尝试这样做
\node [blue] at (2,0) {$\circ$};
\addplot[thick, samples=50, smooth,domain=0:6,magenta, name path=three] coordinates {(2,-1)(2,3)};
\node [red] at (3,0.1) {\textbullet};
两者都失败了
答案1
窃取改编Jake 对在 TikZ-PGF 中绘制钟形曲线的回答,并且不知道你有什么样的曲线:
\documentclass{standalone}
\usepackage{pgfplots}
\begin{document}
\pgfmathdeclarefunction{gauss}{2}{%
\pgfmathparse{1/(#2*sqrt(2*pi))*exp(-((x-#1)^2)/(2*#2^2))}%
}
\begin{tikzpicture}
\begin{axis}[
no markers, domain=-5:5, samples=100,
axis lines*=left, xlabel=$x$, ylabel=$y$,
every axis y label/.style={at=(current axis.above origin),anchor=south},
every axis x label/.style={at=(current axis.right of origin),anchor=west},
height=5cm, width=12cm,
xtick={0,2}, ytick=\empty,
enlargelimits=false, clip=false, axis on top,
grid = major
]
\addplot [fill=cyan!20, draw=none, domain=0:2] {gauss(0,1)} \closedcycle;
\addplot [very thick,cyan!50!black] {gauss(0,1)};
\draw [yshift=-0.6cm, latex-latex](axis cs:0,0) -- node [fill=white] {$a$} (axis cs:0,0);
\draw [yshift=-0.6cm, latex-latex](axis cs:2,0) -- node [fill=white] {$b$} (axis cs:2,0);
\end{axis}
\end{tikzpicture}
\end{document}