我希望这个问题以前没有在网站上被问过。我最近做了以下代码来分别制作两个图。我在想我们是否可以在执行它们时将两个图放在一起?我发现了这个关联但它与图像的情况有关,而不是与新鲜的情节有关。
\documentclass{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{fillbetween}
\pgfplotsset{width=7cm,compat=1.15,
every axis legend/.append style={at={(0.5,-0.1)},anchor=north ,draw=none}}
\begin{document}
\begin{tikzpicture}
\def\verticalbar{2}
\begin{axis}[domain=-0.5:4.5,
grid=major,
legend columns=4,
samples=25,
smooth,
width=7cm, height=7cm,
axis lines = middle,
xlabel = $x$, ylabel = {$y$},
xtick={-2,...,8}];
\addplot [name path=A, thick, blue,dashed,domain=0:4.5] {4*x-x^2};
\addlegendentry{$f=4x-x^2$}
\addplot [name path=B,ultra thick, red] {7-x};
\addlegendentry{$g=7-x$}
\draw [name path=C, dotted, thick] (1,0) -- (1,6);
\draw [name path=D, dashed, thick] (4,0) -- (4,4);
\addplot [gray!40] fill between [
of=A and B, soft clip={domain=1:4},];
\end{axis}
\end{tikzpicture}
\end{document}
我的意思是我们的输出如下: