阴影表示 x 和 y 的两个线性不等式系统的解集

阴影表示 x 和 y 的两个线性不等式系统的解集

我试图以图形方式展示线性不等式系统的解

\begin{equation*}

\begin{cases}
7x + 3y \geq 21 \\
-x + 3y < -3
\end{cases}
.
\end{equation*}

我想对显示进行一些修改。首先,我将pattern=north east lines解决方案设置为7x + 3y \geq 21。线条太近了。我不想要边界。其次,当我尝试使用 编译代码时出现错误pattern=south east lines。第三,我不希望这些指示解决方案集的线条干扰刻度标记。

\documentclass{amsart}

\usepackage{tikz}
\usetikzlibrary{calc,angles,positioning,intersections,quotes,decorations.markings,backgrounds,patterns}

\usepackage{pgfplots}
\pgfplotsset{compat=1.11}


\begin{document}

\begin{center}\Large{\bf Algebra 2}\end{center}\vskip0.3in

\noindent \hspace*{\fill}
\begin{tikzpicture}
\begin{axis}[width=6in,grid=both,grid style={line width=.1pt, draw=gray!10},
    axis equal image,
    axis lines=middle,
    xmin=-11,xmax=11,
    ymin=-11,ymax=11,
    restrict y to domain=-11:11,
    xtick={},ytick={},
    ticklabel style={font=\tiny,fill=white},
    enlargelimits={abs=0.25cm},
    axis line style={latex-latex},
    axis line style={shorten >=-7.5pt, shorten <=-7.5pt},
    xlabel=$x$,
    ylabel=$y$,
    xlabel style={at={(ticklabel* cs:1)},anchor=north west},
    ylabel style={at={(ticklabel* cs:1)},anchor=south west}
]


\coordinate (P) at (-9/7,10);
\coordinate (Q) at (10,10);
\coordinate (R) at (10,-10);
\coordinate (S) at (51/7,-10);

\draw[pattern=north east lines] (P) -- (Q) -- (R) -- (S);


\coordinate (P1) at (-10,-13/3);
\coordinate (Q1) at (10,7/3);
\coordinate (R1) at (10,-10);
\coordinate (S1) at (-10,-10);

%\draw[pattern=south east lines] (P1) -- (Q1) -- (R1) -- (S1);

\addplot[latex-latex,samples=2,domain=-1.5:7.5,blue] {(-7/3)*x + 7};
\addplot[latex-latex,samples=2,domain=-10:10,dashed,green] {(1/3)*x -1};

\node[anchor=north west] at (axis description cs:1,0.5) {$x$};
\node[anchor=north west] at (axis description cs:0.5,1) {$y$};

\end{axis}
\end{tikzpicture}

\end{document}

答案1

不太喜欢这个,但我认为这是你想要的:

在此处输入图片描述

笔记:

  • 模式不容易改变。我使用了代码形式我可以控制 TikZ 中图案的“密度”吗?允许更改线条之间的间距。可以通过 更改下方线条的密度line space=<dimen>

  • 沿着图案的边框已通过draw=none选项禁用。

  • 添加axis on top选项允许轴和刻度标签位于顶部。

  • 没有south east lines图案,但有north west lines。我已my north west lines根据需要应用了 来改变线条之间的间距。

代码:

\documentclass{amsart}

\usepackage{tikz}
\usetikzlibrary{calc,angles,positioning,intersections,quotes,decorations.markings,backgrounds,patterns}

\usepackage{pgfplots}
\pgfplotsset{compat=1.11}

%% https://tex.stackexchange.com/questions/29808/can-i-control-the-density-of-a-pattern-in-tikz
\pgfdeclarepatternformonly[\LineSpace]{my north east lines}{\pgfqpoint{-1pt}{-1pt}}{\pgfqpoint{\LineSpace}{\LineSpace}}{\pgfqpoint{\LineSpace}{\LineSpace}}%
{
    \pgfsetlinewidth{0.4pt}
    \pgfpathmoveto{\pgfqpoint{0pt}{0pt}}
    \pgfpathlineto{\pgfqpoint{\LineSpace + 0.1pt}{\LineSpace + 0.1pt}}
    \pgfusepath{stroke}
}

\pgfdeclarepatternformonly[\LineSpace]{my north west lines}{\pgfqpoint{-1pt}{-1pt}}{\pgfqpoint{\LineSpace}{\LineSpace}}{\pgfqpoint{\LineSpace}{\LineSpace}}%
{
    \pgfsetlinewidth{0.4pt}
    \pgfpathmoveto{\pgfqpoint{0pt}{\LineSpace}}
    \pgfpathlineto{\pgfqpoint{\LineSpace + 0.1pt}{-0.1pt}}
    \pgfusepath{stroke}
}

\newdimen\LineSpace
\tikzset{
    line space/.code={\LineSpace=#1},
    line space=3pt
}
\begin{document}

\begin{center}\Large{\bf Algebra 2}\end{center}\vskip0.3in

\noindent \hspace*{\fill}
\begin{tikzpicture}
\begin{axis}[width=6in,grid=both,grid style={line width=.1pt, draw=gray!10},
    axis equal image,
    axis lines=middle,
    xmin=-11,xmax=11,
    ymin=-11,ymax=11,
    restrict y to domain=-11:11,
    xtick={},ytick={},
    ticklabel style={font=\tiny,fill=white},
    enlargelimits={abs=0.25cm},
    axis line style={latex-latex},
    axis line style={shorten >=-7.5pt, shorten <=-7.5pt},
    xlabel=$x$,
    ylabel=$y$,
    xlabel style={at={(ticklabel* cs:1)},anchor=north west},
    ylabel style={at={(ticklabel* cs:1)},anchor=south west},
    axis on top,
]


\coordinate (P) at (-9/7,10);
\coordinate (Q) at (10,10);
\coordinate (R) at (10,-10);
\coordinate (S) at (51/7,-10);

%% Adjust density of the lines by changing the `line space=` value.
\draw[pattern=my north west lines, draw=none, line space=10pt] (P) -- (Q) -- (R) -- (S);


\coordinate (P1) at (-10,-13/3);
\coordinate (Q1) at (10,7/3);
\coordinate (R1) at (10,-10);
\coordinate (S1) at (-10,-10);

%\draw[pattern=south east lines] (P1) -- (Q1) -- (R1) -- (S1);

\addplot[latex-latex,samples=2,domain=-1.5:7.5,blue, ultra thick] {(-7/3)*x + 7};
\addplot[latex-latex,samples=2,domain=-10:10.4,dashed,orange, thick] {(1/3)*x -1};

\node[anchor=north west] at (axis description cs:1,0.5) {$x$};
\node[anchor=north west] at (axis description cs:0.5,1) {$y$};

\end{axis}
\end{tikzpicture}

\end{document}

相关内容