在以下示例中:
\documentclass{article}
\usepackage{tikz, pgfplots}
\usepgfplotslibrary{fillbetween}
\pgfplotsset{compat=1.14}
\begin{document}
\begin{tikzpicture}
\begin{axis}
\addplot [name path = plot1] coordinates {
(0, 2)
(2, 5)
(3, 7)
};
\draw [name path = plot2] (0, 2) -- (5, 2);
\end{axis}
\end{tikzpicture}
\end{document}
如结果所示,路径plot2
超出了范围:axis
如何使axis
调整本身尽可能地包围路径,plot2
就像调整包围路径一样plot1
?
答案1
pgpflots
\path
计算边界框时不考虑s,但您可以\addplot
改为用 绘制线条。如果线条不可见,请添加draw=none
到\addplot
设置中。
\documentclass{article}
\usepackage{pgfplots}
\usepgfplotslibrary{fillbetween}
\pgfplotsset{compat=1.14}
\begin{document}
\begin{tikzpicture}
\begin{axis}
\addplot [name path = plot1] coordinates {
(0, 2)
(2, 5)
(3, 7)
} coordinate (end);
\addplot [draw=none,name path = plot2] coordinates {(0, 2)(5, 2)};
\addplot [blue!10] fill between[of=plot1 and plot2];
\end{axis}
\end{tikzpicture}
\end{document}