pgfplots
我正在尝试使用网格坐标向图中添加带有节点的注释axis
,这比使用绝对坐标更方便。我想添加一个箭头来指出下图中的高斯宽度
我成功地做到了
\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}
\begin{document}
\begin{tikzpicture}
\begin{axis}
[
grid = both,
]
\addplot
[
samples = 100,
color = blue!80,
thick,
] {exp(-0.5*((x/2)^6)};
\draw [thick, <->] (-2, 0.6) -- (2, 0.6);
\draw (0, 0.65) node [above] {critical diameter};
\end{axis}
\end{tikzpicture}
\end{document}
这使
但如果我没有pgfplots
在向后兼容模式下运行(即\pgfplotsset{compat=1.11}
从后面的代码中删除了 if ),它会产生
我相信pgfplots
在较新版本中不再默认使用网格坐标,并且我想了解如何使用网格坐标与最新版本的向后兼容产生相同的结果pgfplots
。
感谢您的帮助!
答案1
查看代码中的注释以获得解释和解决方案。
% used PGFPlots v1.16
\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.10}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
grid=both,
]
\addplot[
samples = 100,
color = blue!80,
thick,
] {exp(-0.5*(x/2)^6)};
% by default up to `compat=1.10` the Tikz coordinate system is used
% starting with `compat=1.11` the `axis` coordinate system is used
\draw [thick, <->] (-2, 0.6) -- (2, 0.6)
node [midway,above,red] {critical diameter}
;
% to be sure that the `axis` coordinates are used,
% give them the prefix `axis cs:`
\draw [thick, <->] (axis cs:-2, 0.6) -- (axis cs:2, 0.6)
node [midway,above,green] {critical diameter}
;
\end{axis}
\end{tikzpicture}
\end{document}
答案2
尝试
\documentclass{standalone}
\usepackage{pgfplots}
%\pgfplotsset{compat=1.16}
\begin{document}
\begin{tikzpicture}
\begin{axis}[grid]
\addplot
[
samples = 100,
color = blue!80,
thick,
] {exp(-0.5*((x/2)^6)};
\draw [thick, <->] (axis cs: -2, 0.6) -- node[above,font=\footnotesize] {critical diameter} (axis cs: 2, 0.6);
\end{axis}
\end{tikzpicture}
\end{document}