我正在尝试使用方法大纲 图形:曲线之间的面积 创建两条曲线之间面积的图表以插入解决方案表。但是,当我这样做时,框的位置不正确。tikzpicture 最终比它应该的位置高得多,而不是排成一行,因此覆盖了文本或放置在其上方的其他图片。我的代码如下:
\documentclass[11pt]{article}
\usepackage{tikz}
\usepackage{pgfplots}
\usepgfplotslibrary{fillbetween}
\usetikzlibrary{patterns}
\begin{document}
The box for the tikzpicture appears to be much higher than it should be.\\
{\begin{tikzpicture}[scale=0.75]
\begin{axis}[
xmin=0,xmax=5,
ymin=-1, ymax=6,
xtick = {-1,1},
ytick = {1,2,3,4,5,6},
axis lines=center,
axis line style = <->,
ticklabel style = {font=\small}
]
\addplot[name path=F,domain={0:5}] {x};
\addplot[name path=G,domain={0:5}] {(x-2)^2};
\addplot[pattern=north west lines, pattern color=gray!50]fill between[of=F and G, soft clip={domain=1:4}];
\end{axis}
\end{tikzpicture}}
\end{document}
答案1
正如我在在问题下方评论 我认为这是一个错误,我已将其报告给PGFPlots 追踪器。
有一种解决方法可以得到所需的结果。查看代码中的注释以了解如何操作。
\documentclass[11pt]{article}
\usepackage{pgfplots}
\usetikzlibrary{
patterns,
pgfplots.fillbetween,
}
\begin{document}
The box for the tikzpicture appears to be much higher than it should be.
\begin{tikzpicture}[
% this line causes the mess ...
% scale=0.75,
]
\begin{axis}[
% ... as a workaround just scale the default axis `width' directly with
% the factor to get the desired result
width=0.75*\axisdefaultwidth,
xmin=0, xmax=5,
ymin=-1, ymax=6,
xtick={-1,1},
ytick={1,2,3,4,5,6},
axis lines=center,
axis line style=<->,
ticklabel style={font=\small}
]
\addplot [name path=F,domain={0:5}] {x};
\addplot [name path=G,domain={0:5}] {(x-2)^2};
\addplot [
pattern=north west lines,
pattern color=gray!50,
] fill between [
of=F and G,
soft clip={domain=1:4},
];
\end{axis}
\end{tikzpicture}
\end{document}