我试图填充绿线和红线上方、两条棕色线之间。我尝试使用软剪辑和域,但无法正常工作。以下是我想要实现的目标(粗线条或仅填充此空间)。
目前的代码是:
\documentclass{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\usepgfplotslibrary{fillbetween}
\usetikzlibrary{patterns}
\begin{document}
\begin{tikzpicture}
\begin{axis}[grid=both,ymin=-5,ymax=5,xmax=5,xmin=-5,xticklabel=\empty,yticklabel=\empty,
minor tick num=1,axis lines = middle,xlabel=$x_1$,ylabel=$x_2$,label style =
{at={(ticklabel cs:1.1)}}]
\addplot[draw=green, name path=A]{7/2 -2*x};
\addplot[draw=red, name path=B]{3/2 - x/2};
\addplot[draw=blue, name path=C]{1- x/3};
\addplot +[mark=none,draw=brown, name path=D] coordinates {(1,-6) (1,6)};
\addplot +[mark=none,draw=brown, name path=E] coordinates {(2,-6) (2,6)};
\end{axis}
\end{tikzpicture}
\end{document}
提前致谢!
答案1
您可能只使用剪辑。
\documentclass{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{fillbetween}
\usetikzlibrary{patterns.meta}
\pgfplotsset{compat=1.17}
\begin{document}
\begin{tikzpicture}
\begin{axis}[grid=both,ymin=-5,ymax=5,xmax=5,xmin=-5,xticklabel=\empty,yticklabel=\empty,
minor tick num=1,axis lines = middle,xlabel=$x_1$,ylabel=$x_2$,label style =
{at={(ticklabel cs:1.1)}}]
\addplot[draw=green, name path=A,samples=2]{7/2 -2*x}
coordinate[pos=0] (A0) coordinate[pos=1] (A1);
\addplot[draw=red, name path=B,samples=2]{3/2 - x/2}
coordinate[pos=0] (B0) coordinate[pos=1] (B1);
\addplot[draw=blue, name path=C,samples=2]{1- x/3}
coordinate[pos=0] (C0) coordinate[pos=1] (C1);
\path (\pgfkeysvalueof{/pgfplots/xmin},\pgfkeysvalueof{/pgfplots/ymax})
coordinate (TL) (\pgfkeysvalueof{/pgfplots/xmax},\pgfkeysvalueof{/pgfplots/ymax})
coordinate (TR);
\begin{scope}
\clip (TL) -- (A0) -- (A1) -- (TR) -- cycle;
\clip (TL) -- (B0) -- (B1) -- (TR) -- cycle;
\clip (TL) -- (C0) -- (C1) -- (TR) -- cycle;
\path[pattern={Lines[angle=45]},pattern color=red] (1,-6) rectangle (2,6);
\end{scope}
\addplot +[mark=none,draw=brown, name path=D] coordinates {(1,-6) (1,6)};
\addplot +[mark=none,draw=brown, name path=E] coordinates {(2,-6) (2,6)};
\end{axis}
\end{tikzpicture}
\end{document}