PGFplots allows you to use all the usual functions from Ti*k*Z within its `{axis}`

environment. You have access to the coordinate system through `axis cs`

so that `\node at (axis cs: 3, 4) {};`

places a node at the *x*-*y* coordinate `(3, 4)`

. In version 1.11, `axis cs`

became the default coordinate system used by Ti*k*Z within the `{axis}`

environments so you need not specify `axis cs`

every time and instead can just type `\node at (3, 4) {};`

.

I provide below two very similar ways of drawing (what I think) you want. Both of them plot the two relevant curves (`x`

and `6 / (5 - x)`

), but the first one also uses the *x*-axis as the number line whilst the second one places the number line above the the plot.

## Version 1: All in One

This solution uses the one set of axes to both display the appropriate equations for the inequality and label the part of the number line for which the inequality holds true:

```
\documentclass{amsart}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amsthm}
\usepackage{thmtools}
\declaretheoremstyle[
headfont=\normalfont\bfseries,
numbered=unless unique,
bodyfont=\normalfont,
spaceabove=1em plus 0.75em minus 0.25em,
spacebelow=1em plus 0.75em minus 0.25em,
qed={\rule{1.5ex}{1.5ex}},
]{solstyle}
\declaretheorem[
style=solstyle,
title=Solution,
refname={solution,solutions},
Refname={Solution,Solutions}
]{solution}
\usepackage{enumitem}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.13}
\begin{document}
\begin{enumerate}[label=\bfseries\arabic*)]
\item Determine the solution set to
\begin{equation*}
\frac{6}{x - 5} \geq x .
\end{equation*}
Graph the solution set on the real number line.
\begin{solution}
We first observe that there is a singularity at \(x = 5\) as we consider the
region above and below \(5\) separately:
\begin{description}
\item[\(\boldsymbol{x > 5}\)] Over this interval, the denominator is always
greater than zero. As a result, multiplying both sides by \(x-5\) we
obtain:
\begin{align*}
& 6 \geq x^{2} - 5x \\
\Leftrightarrow & 0 \geq x^{2} - 5x - 6 = (x-6)(x+1)
\end{align*}
Over the given domain, \(x+1\) is always positive; therefore, we must have
that \(x-6 \leq 0\) and conclude that the inequality is satisfied only for
\(5 < x \leq 6\).
\item[\(\boldsymbol{x < 5}\)] Over this internal, the denominator is always
less than zero. As a result, multiplying both sides by \(x-5\) flips the
inequality and we obtain:
\begin{align*}
& 6 \leq x^{2} - 5x \\
\Leftrightarrow & 0 \leq x^{2} - 5x - 6 = (x-6)(x+1)
\end{align*}
Over the given domain, \(x-6\) is always negative; therefore, we must have
that \(x+1 \leq 0\) and conclude that the inequality is satisfied only for
\(x \leq -1\).
\end{description}
The two relevant curves for this inequality are plotted below with the
appropriate domain marked in red along the \(x\)-axis:
\begin{center}
\begin{tikzpicture}
\begin{axis}[
width=\linewidth,
height=0.7\linewidth,
axis lines=middle,
xlabel=\(x\),
ylabel=\(y\),
xlabel style={at={(ticklabel* cs:1)},anchor=west},
ylabel style={at={(ticklabel* cs:1)},anchor=south},
clip=false,
domain=-5:10,
samples=501,
restrict y to domain=-10:16,
clip=false,
]
\addplot [blue] {6/(x - 5)}
node [above, pos=0.95, font=\footnotesize] {\(y=\dfrac{6}{x-5}\)};
\addplot [latex-latex] {x}
node[anchor=west, pos=1, font=\footnotesize]{\(y=x\)};
\draw [dashed, latex-latex]
(5,\pgfkeysvalueof{/pgfplots/ymin}) -- (5, \pgfkeysvalueof{/pgfplots/ymax})
node [pos=0.05, below, sloped, font=\footnotesize] {\(x=5\)};
\fill [blue] (-1, -1) circle [radius=2pt]
node [anchor=north, font=\footnotesize] {\((-1, -1)\)};
\fill [blue] (6, 6) circle [radius=2pt]
node [anchor=west, font=\footnotesize] {\((6, 6)\)};
\draw [-latex, red, very thick] (-1, 0) -- (\pgfkeysvalueof{/pgfplots/xmin}, 0);
\draw [red, very thick] (5, 0) -- (6, 0);
\fill [black] (-1, 0) circle [radius=2pt];
\draw [draw=black, fill=white] (5, 0) circle [radius=2pt];
\fill [black] (6, 0) circle [radius=2pt];
\end{axis}
\end{tikzpicture}
\end{center}
\end{solution}
\end{enumerate}
\end{document}
```

## Version 2: Number line on top

If you want to have the number line separate from the axis (as you intend to in the original question), you basically had it all right:

```
\begin{center}
\begin{tikzpicture}
\begin{axis}[
name=plot1,
width=\linewidth,
height=11em,
axis x line=middle,
axis y line=none,
clip=false,
domain=-5:10,
axis line style={latex-latex},
]
\addplot [draw=none] {0};
\draw [-latex, red, very thick] (-1, 0) -- (\pgfkeysvalueof{/pgfplots/xmin}, 0);
\draw [red, very thick] (5, 0) -- (6, 0)
node [above, pos=0] {\(5\)}
node [above, pos=1] {\(6\)};
\fill [black] (-1, 0) circle [radius=2pt]
node [red, above] {\(-1\)};
\draw [draw=black, fill=white] (5, 0) circle [radius=2pt];
\fill [black] (6, 0) circle [radius=2pt];
\end{axis}
\begin{axis}[
at=(plot1.south),
anchor=north,
width=\linewidth,
height=0.7\linewidth,
axis lines=middle,
xlabel=\(x\),
ylabel=\(y\),
xlabel style={at={(ticklabel* cs:1)},anchor=west},
ylabel style={at={(ticklabel* cs:1)},anchor=south},
clip=false,
domain=-5:10,
samples=501,
restrict y to domain=-10:16,
clip=false,
]
\addplot [blue] {6/(x - 5)}
node [above, pos=0.95, font=\footnotesize] {\(y=\dfrac{6}{x-5}\)};
\addplot [latex-latex] {x}
node[anchor=west, pos=1, font=\footnotesize]{\(y=x\)};
\draw [dashed, latex-latex]
(5,\pgfkeysvalueof{/pgfplots/ymin}) -- (5, \pgfkeysvalueof{/pgfplots/ymax})
node [pos=0.05, below, sloped, font=\footnotesize] {\(x=5\)};
\fill [blue] (-1, -1) circle [radius=2pt]
node [anchor=north, font=\footnotesize] {\((-1, -1)\)};
\fill [blue] (6, 6) circle [radius=2pt]
node [anchor=west, font=\footnotesize] {\((6, 6)\)};
\end{axis}
\end{tikzpicture}
\end{center}
```

### Extra Notes

Firstly, I took the liberty of cleaning up your example and make use of environments such as `enumerate`

, `description`

and created a `solution`

environment to take care of the formatting for you automatically. Although having `\texbf{1) }`

and `\vskip1em`

do work, it isn't really the best way to use LaTeX. You should write what you *mean* instead of writing what you want to *see*. That is, instead of `\textbf{1) }`

, `\textbf{2) }`

, have an enumerated list; and instead of `\textbf{Solution: } ... \rule{1.5ex}{1.5ex}`

, have a `{solution}`

environment.

The advantage of writing what you *mean* is that if you want to change the way solutions look, you can do it in one place instead of having to go through your whole document and changing every instance.

A few other small things:

- For some reason, the
`{axis}`

environment seems to require having at least one `\addplot`

command. I suspect that it is because it needs that to calculate the range of both axes even if `xmin`

, `xmax,`

`ymin`

and `ymax`

are all specified. Since I don't want to actually plot anything for the number line, I used `\addplot [draw=none] {0};`

. I can't seem to find any mention of this requirement within the PGFplots documentation.
- When PGFplots calculates the positioning of all the labels, it seems to require a minimum height. When drawing the number line, I initially used a
`height=0pt`

, but this resulted in errors so instead I used `height=11em`

. This has the additional benefit that I no longer need adjust the `plot1.south`

coordinate as the vertical height of the baseline is enough.
- Instead of declaring
`samples`

and `domain`

with every `\addplot`

call, I declare these properties for the whole axis. This makes the code a little cleaner and also ensures that all the plots are drawn over the whole domain (for example, I'd rather not have the line `y=x`

stop half-way). If that is intended behaviour though, having `\addplot [domain=-5:0] {x};`

will override the axis-wide `domain`

.
- Similar to the previous note, having
`restrict y to domain`

in the `{axis}`

options make that change work for every `\addplot`

command in that environment. In addition, `restrict y to domain`

discards points which are outside of the specified domain. You don't need to plot `6 / (5-x)`

in two separate `\addplot`

calls because any value which end up outside of the specified *y* domain are automatically discarded.
- With regards to the two previous points, think of
`domain`

and `restrict y to domain`

as settings the overall view port for the whole graph, and PGFplots will then figure out what to draw.
- I use
`\pgfkeysvalueof{/pgfplots/xmin}`

(and analogous) in order to obtain the value of `xmin`

, `ymin`

and `ymax`

instead of hard-coding them. This means that if I want to change where the *y*-axis starts and stops, the asymptote line will automatically adjust.
- Instead of using
`\addplot`

to draw the line `x=5`

, I use explicit coordinates. This is mostly because I found the PGFplots behaviour to be slightly inconsistent sometimes.
- Instead of using
`\addplot coordinates{-1,-1};`

to draw a single point, I used one of the basic Ti*k*Z commands. Firstly, we aren't really plotting another curve, but instead annotating it, so `\addplot`

already doesn't feel like what we need. Additionally, having the extra `\addplot`

command will mess around with legend entries and the plot style cycle, hence why you initial plot had various shapes and colours despite you not specifying them.
- I chose
`width=\linewidth`

so that the plot fills the width of the current line. As for `height=0.7\linewidth`

, it is arbitrary (I could have used `height=5cm`

) but the rationale for using `\linewidth`

is that if I change the formatting of the document, the aspect ratio of the plot width and height remains the same and it is always guaranteed to take up the width of the line. As for the `0.7`

in particular, I typically use `0.62`

because that ensure the plot follows the golden ratio, but in the particular case of this graph I thought it looked a little too squashed so instead I used `0.7`

.

## Best Answer

You can solve the issue by added

`set layers`

to your axis. This activates layered graphics for your`tikzpicture`

, and the layers are drawn in the correct sequence. The default is to the single axes individually, which can cause the observed effect. Setting`set layers`

should not have any negative effect on the appearance and the small additional runtime cost is probably irrelevant.The feature

`set layers`

is relatively new and requires pgfplots 1.7Perhaps this should become the default eventually...