我想绘制可行区域。但我不知道该怎么做。我需要指导。
\documentclass[tikz, border=5mm]{standalone}
\begin{document}
\begin{tikzpicture}
\draw[gray!50, thin, step=0.5] (-1,-3) grid (5,4);
\draw[very thick,->] (-1,0) -- (5.2,0) node[right] {$x_1$};
\draw[very thick,->] (0,-3) -- (0,4.2) node[above] {$x_2$};
\foreach \x in {-1,...,5} \draw (\x,0.05) -- (\x,-0.05) node[below] {\tiny\x};
\foreach \y in {-3,...,4} \draw (-0.05,\y) -- (0.05,\y) node[right] {\tiny\y};
\draw (-1,-3) -- node[above,sloped] {\tiny$x_1=-1$} (-1,3);
\draw (0,0) -- node[above,sloped] {\tiny$x_1\leq x_2$} (3,3);
\draw (0,0) -- node[above,sloped] {\tiny$x_1\leq x_2$} (3,-3);
\draw (-1,3) -- node[above,sloped] {\tiny$x_2=3$} (3,3);
\draw (-1,3) -- node[above,sloped] {\tiny$x_2=-3$} (3,3);
\end{tikzpicture}
\end{document}
目前结果:
答案1
我不确定结果应该是什么样子,但也许这可以帮助你。
如果要绘制一个区域,则应连接表示该区域边界的线条,否则得到的只是未连接的单线。此外,如果该区域不应覆盖图表的某些部分,则应将其放在不应覆盖的内容之前:
\documentclass[tikz, border=10pt]{standalone}
\begin{document}
\begin{tikzpicture}
\draw[gray!50, thin, step=0.5] (-1,-3) grid (5,4);
\draw[fill=gray!10]
(-1,-3)
-- node[above, sloped] {\tiny$x_1=-1$} (-1,3)
-- node[above, sloped] {\tiny$x_2=3$} (3,3)
-- node[above, sloped] {\tiny$x_1\leq x_2$} (0,0)
-- node[above, sloped] {\tiny$x_1\leq -x_2$} (3,-3)
-- node[above, sloped] {\tiny$x_2=-3$} cycle;
\draw[very thick, ->] (-1,0) -- (5.2,0) node[right] {$x_1$};
\draw[very thick, ->] (0,-3) -- (0,4.2) node[above] {$x_2$};
\foreach \x in {-1,...,5}
\draw (\x,0.05) -- (\x,-0.05)
\ifnum\x=0\relax
node[below right] {\tiny\x}
\else
node[below] {\tiny\x}
\fi ;
\foreach \y in {-3,...,4}
\draw (-0.05,\y) -- (0.05,\y)
\ifnum\y=0\else
node[right] {\tiny\y}
\fi ;
\draw[very thick, <->]
(0:2) arc[start angle=0, end angle=45, radius=2]
node[midway, right] {\tiny$q$};
\node[align=center] at (3,-2) {unstable \\ region};
\node[align=center] at (1,-2) {stable \\ region};
\end{tikzpicture}
\end{document}
删除大多数标签和网格后,它看起来更像您展示的图片:
\documentclass[tikz, border=10pt]{standalone}
\begin{document}
\begin{tikzpicture}
\draw[fill=gray!10]
(-1,-3) -- (-1,3) -- (3,3) -- (0,0) -- (3,-3) -- cycle;
\draw[very thick, ->] (-1,0) -- (3,0) node[right] {$x_1$};
\draw[very thick, ->] (0,-3) -- (0,3.5) node[above] {$x_2$};
\draw[very thick, <->]
(0:2) arc[start angle=0, end angle=45, radius=2]
node[midway, right] {$q$};
\node[align=center] at (3,-2) {unstable \\ region};
\node[align=center] at (1,-2) {stable \\ region};
\end{tikzpicture}
\end{document}