2

I am trying to graph a basic linear inequality (y < -2x + 5).

I started something. I could figure out how to graph y = -2x + 5.

In short what I'm trying to get:

enter image description here

What I currently have:

enter image description here

The code for what I have:

\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}

\begin{document}
    
    \begin{tikzpicture}[scale=1]
        \begin{axis}[x=1cm,y=1cm,
            axis lines = middle,
            xlabel = {$x$},
            ylabel = {$y$},
            xmin=-5, xmax=5,
            ymin=-5, ymax=5,small,
            grid]
            
            \addplot [
            domain = -5:5,
            samples = 1000,blue,very thick] {-2*x+5} 
            node [pos=.65, right] {};

        \end{axis}
    \end{tikzpicture}
\end{document}

Any help would be appreciated!

1 Answer 1

4

Like this:

enter image description here

Code:

\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}

\begin{document}
    
    \begin{tikzpicture}[scale=1]
        \begin{axis}[x=1cm,y=1cm,
            axis lines = middle,
            xlabel = {$x$},
            ylabel = {$y$},
            xmin=-5, xmax=5,
            ymin=-5, ymax=7,small, % changed
            grid]
            
            \addplot [dashed, % changed
            domain = -5:5,
            samples = 1000,blue,very thick] {-2*x+5} 
            node [pos=.65, right] {};
            \fill[red!30,opacity=.5] (-5,-5) rectangle (-1,7); % added
            \fill[red!30,opacity=.5] (-1,-5)--(5,-5)-- (-1,7); % added
        \end{axis}
    \end{tikzpicture}
\end{document}
2
  • Super helpful! I try messing around to learn how else I could shade based on what you had above (I think I got the hang of the shading. Like you did a rectangle and a triangle). Very very helpful! Thanks so much Jun 5 at 3:54
  • You are wellcome! Jun 5 at 8:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .