Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

The following code I got from: http://tex.stackexchange.com/a/76014/10898

enter image description here

\documentclass{article} 

\usepackage{pgfplots} 
\usetikzlibrary{patterns}

\makeatletter
\newcommand{\pgfplotsdrawaxis}{\pgfplots@draw@axis}
\makeatother
\pgfplotsset{only axis on top/.style={axis on top=false, after end axis/.code={
             \pgfplotsset{axis line style=opaque, ticklabel style=opaque, tick style=opaque,
                          grid=none}\pgfplotsdrawaxis}}}

\newcommand{\drawge}{-- (rel axis cs:1,0) -- (rel axis cs:1,1) -- (rel axis cs:0,1) \closedcycle}
\newcommand{\drawle}{-- (rel axis cs:1,1) -- (rel axis cs:1,0) -- (rel axis cs:0,0) \closedcycle}

\begin{document} 
  \begin{figure}[htpb] 
    \centering 
    \label{fig:p3:c1} 
    \begin{tikzpicture} 
      \begin{axis}[only axis on top,
        axis line style=very thick, 
        axis x line=middle, 
        axis y line=middle, 
         ymin=-1,ymax=5.99,xmin=-1,xmax=5.99, 
         xlabel=$x$, ylabel=$y$,grid=major 
      ] 
        \addplot [draw=none, pattern=north west lines, pattern color=blue!40, domain=-10:12]
                 {3-3/2*x} \drawge;
        \addplot[very thick, domain=-1:2.5,<->] {3-3/2*x}; 
      \end{axis} 
    \end{tikzpicture} 
    \caption{Problem 4, Part A} 
  \end{figure} 

\end{document}

The question here is how can I get it to work with a setting like the following:

enter image description here

\documentclass[dvipsnames]{article}
\usepackage{amsmath,pgfplots,tikz}
\usetikzlibrary{arrows,calc}
\begin{document}

    \begin{tikzpicture}[transform shape,scale=0.6]
    \draw[step=1cm,gray,very thin] (-4,-3) grid (4,5);
    \draw [-latex,thick](-4,0) -- (4,0) node[right] {$x$} coordinate(x axis);
    \foreach \x in {-3,-2,-1,1,2,3}
             \draw (\x,0.1) -- (\x,-0.1) node [fill=white,below] {$\x$};
    \foreach \y in {-2,-1,1,2,3,4}
             \draw (0.1,\y) -- (-0.1,\y) node [fill=white,left] {$\y$};
    \draw [-latex,thick](0,-3) -- (0,5) node[above] {$y$} coordinate(y axis);
    \node at (-0.25,-0.3375) {0};
    \draw[color=Cerulean,latex-latex,domain=-1.3:4] plot (\x,-3/2*\x+3);
    \filldraw[OrangeRed] (0,3) circle (1.5pt) node[inner sep=2pt,right,fill=white,shift={(0.25,0)}] {$(0,3)$};
    \filldraw[OrangeRed] (2,0) circle (1.5pt) node[inner sep=2pt,right,fill=white,shift={(0.25,0.35)}] {$(2,0)$};
    \end{tikzpicture}
\end{document}

That is, I would like to represent the solution set of the inequality in a similar manner as is done using pgfplots in my last example above. Is this possible?

share|improve this question

2 Answers 2

This is a possible solution. Adding one line of draw command with pattern and pattern color, display below. patterns from tikzlibrary is required.

If want to hide the coordinates (0,3), (2,0) behind the pattern line, move the following draw line to the last of the code.

\draw[draw=none,pattern=north west lines, pattern color=blue!40](-1.3,5)--(4,-3)--(4,5)--cycle;

enter image description here

Code

\documentclass[dvipsnames]{article}
\usepackage[paper size={8cm, 8cm}]{geometry}
\usepackage{amsmath,pgfplots,tikz}
\usetikzlibrary{arrows,calc}
\usetikzlibrary{decorations.pathmorphing,patterns}
\begin{document}

    \begin{tikzpicture}[transform shape,scale=0.6]
    \draw[step=1cm,gray,very thin] (-4,-3) grid (4,5);
    \draw [-latex,thick](-4,0) -- (4,0) node[right] {$x$} coordinate(x axis);
    \foreach \x in {-3,-2,-1,1,2,3}
             \draw (\x,0.1) -- (\x,-0.1) node [fill=white,below] {$\x$};
    \foreach \y in {-2,-1,1,2,3,4}
             \draw (0.1,\y) -- (-0.1,\y) node [fill=white,left] {$\y$};
    \draw [-latex,thick](0,-3) -- (0,5) node[above] {$y$} coordinate(y axis);
    \node at (-0.25,-0.3375) {0};
\draw[draw=none,pattern=north west lines, pattern color=blue!40](-1.3,5)--(4,-3)--(4,5)--cycle;
\draw[color=Cerulean,latex-latex,domain=-1.3:4] plot (\x,-3/2*\x+3);
\filldraw[OrangeRed] (0,3) circle (1.5pt) node[inner sep=2pt,right,fill=white,shift={(0.25,0)}] {$(0,3)$};
    \filldraw[OrangeRed] (2,0) circle (1.5pt) node[inner sep=2pt,right,fill=white,shift={(0.25,0.35)}] {$(2,0)$};
\end{tikzpicture}
\end{document}
share|improve this answer
\documentclass[dvipsnames]{article}

\usepackage{pgfplots}
\usetikzlibrary{patterns}

\makeatletter
\newcommand{\pgfplotsdrawaxis}{\pgfplots@draw@axis}
\makeatother
\pgfplotsset{only axis on top/.style={axis on top=false, after end axis/.code={
             \pgfplotsset{axis line style=opaque, ticklabel style=opaque, tick style={thick,opaque},
                          grid=none}\pgfplotsdrawaxis}}}

\begin{document}
  \begin{figure}[htpb]
    \centering
    \label{fig:p3:c1}
    \begin{tikzpicture}
      \begin{axis}[only axis on top,
        axis line style=very thick,
        axis x line=middle,
        axis y line=middle,
         ymin=-3,ymax=5,xmin=-4,xmax=4,
         %xlabel=$x$, ylabel=$y$,
         xtick={-4,-3,-2,-1,0,1,2,3,4},
         ytick={-3,-2,-1,0,1,2,3,4,5},
         xticklabels={,-3,-2,-1,0,1,2,3},
         yticklabels={,-2,-1,0,1,2,3,4},
         grid=both,clip=false
      ]        
        \draw[draw=none,pattern=north west lines, pattern color=blue!40](axis cs: -1.3,5)--(axis cs: 
                4,-3)--(axis cs: 4,5)--cycle;
        \addplot[Cerulean,very thick,latex-latex,domain=-1.3:4] plot (\x,-3/2*\x+3);
        \node[font=\small] at (axis cs: 4.25,0) {$x$};
        \node[font=\small] at (axis cs: 0,5.25) {$y$};
        \filldraw[OrangeRed] (axis cs: 0,3) circle (2pt) node[inner 
                sep=2pt,right=3mm,fill=white]
           {$(0,3)$};
       \filldraw[OrangeRed] (axis cs:2,0) circle (2pt) node[inner 
             sep=2pt,fill=white,anchor=south west] at (axis cs: 2.1,0.1) {$(2,0)$};
      \end{axis}
    \end{tikzpicture}
    \caption{Problem 4, Part A}
  \end{figure}

\end{document}

enter image description here

Since you wanted x and y labels standing out (which I have to manually put), I had to use clip=false which in turn prevents the use of \drawge command. Hence I chose to fill the pattern manually, like Jesse. I have also adjusted the ticks,ticklabels and the grid.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.