I have two graphical solutions to an inequality (and an algebraic solution to it). One solution is to be displayed on the number line, and the other solution is to be displayed on the Cartesian plane. I want the number line and the x-axis in the Cartesian plane to be aligned vertically.
The inequality is
\begin{equation*}
\frac{6}{x – 5} \geq x
\end{equation*}
and the solution set is $(-\infty,-1) \cup (5,6]$. So, on the first graph, I want tick marks and labels for -1
, 5
, and 6
and a thick line drawn to the left of -1
and between 5
and 6
. With TikZ
, I used the following commands.
\draw[line width=2pt, -latex] ($(-1,0) +(-3pt,0pt)$) -- (-2.9,0);
\draw[fill] (-1,0) circle (3pt);
\draw (5,0) circle (3pt);
\draw[fill] (6,0) circle (3pt);
\draw[line width=2pt] ($(5,0) +(3pt,0pt)$) -- ($(6,0) +(-3pt,0pt)$);
I am not sure what the appropriate commands in pgfplots
would be.
The code for the number line would not compile. I put comment lines in front of most of the commands for the number line.
By the way, I would like the points (-1,-1)
and (6,6)
marked with a black circle or a blue circle. Why is the point (-1,-1)
marked with a blue diamond and the point (6,6)
marked with a red circle?
\documentclass{amsart}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{tikz}
\usetikzlibrary{calc,positioning,intersections}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}
\begin{document}
\noindent {\textbf{1.) }}Determine the solution set to
\begin{equation*}
\frac{6}{x - 5} \geq x .
\end{equation*}
Graph the solution set on the real number line.
\vskip0.2in
\noindent {\bf Solution} \vskip1.25mm
\noindent $q(x) = 6/(x - 5)$ is a rational function defined on ${\mathbb{R}}\setminus\{5\}$. On the interval $(5, \, \infty)$, $q(x) \geq x$ if, and only if,
\begin{equation*}
(x - 6)(x + 1) = x^{2} - 5x - 6 \leq 0 ,
\end{equation*}
or equivalently, $5 < x \leq 6$. Likewise, on the interval $(-\infty, \, 5)$, $q(x) \geq x$ if, and only if, $x \leq -1$. \rule{1.5ex}{1.5ex}
\vskip0.2in
\noindent \hspace*{\fill}
\begin{tikzpicture}
\begin{axis}[name=plot1, %height=0.5in, width=5in, clip=false,
% xmin=-10,xmax=16,
% xlabel=$x$,
% axis line style={latex-latex},
% xtick={},
% extra x ticks={-1,5,6},
% extra x tick labels={$-1$,5,6},
% extra x tick style={xticklabel style={below}},
% xlabel style={at={(ticklabel* cs:1)},anchor=north west}
]
\end{axis}
\begin{axis}[name=plot2, at={($(plot1.south)+(0,-0.75cm)$)}, anchor=north, height=5in, width=5in,
axis lines=middle, clip=false,
xmin=-10,xmax=16,
ymin=-10,ymax=16,
restrict y to domain=-10:16,
xtick={\empty},ytick={\empty},
ticklabel style={font=\tiny,fill=white},
extra x ticks={-1,6},
extra x tick labels={$-1$,6},
axis line style={latex-latex},
xlabel=$x$,ylabel=$y$,
enlargelimits={abs=0.25cm},
xlabel style={at={(ticklabel* cs:1)},anchor=north west},
ylabel style={at={(ticklabel* cs:1)},anchor=south west}
]
\addplot[samples=501,domain=-10:4.4, blue] {6/(x - 5)};
\addplot[samples=501,domain=5.4:16, blue] {6/(x - 5)} node[above,pos=0.9,font=\footnotesize]{$y=\dfrac{6}{x-5}$};
\addplot[latex-latex, samples=2, domain=-10:15] {x} node[anchor=west, pos=1, font=\footnotesize]{$y=x$};
\addplot[dashed, latex-latex, samples=2, domain=-10:16] (5,x) node [pos=0.05, anchor=north, font=\footnotesize, sloped] {$x=5$};
\addplot coordinates{(-1,-1)};
\addplot coordinates{(6,6)} node[anchor=west,font=\footnotesize]{$(6,6)$};
\end{axis}
\end{tikzpicture}
\end{document}
Best Answer
PGFplots allows you to use all the usual functions from TikZ within its
{axis}
environment. You have access to the coordinate system throughaxis 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 TikZ within the{axis}
environments so you need not specifyaxis 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
and6 / (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:
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:
Extra Notes
Firstly, I took the liberty of cleaning up your example and make use of environments such as
enumerate
,description
and created asolution
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:
{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 ifxmin
,xmax,
ymin
andymax
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.height=0pt
, but this resulted in errors so instead I usedheight=11em
. This has the additional benefit that I no longer need adjust theplot1.south
coordinate as the vertical height of the baseline is enough.samples
anddomain
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 liney=x
stop half-way). If that is intended behaviour though, having\addplot [domain=-5:0] {x};
will override the axis-widedomain
.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 plot6 / (5-x)
in two separate\addplot
calls because any value which end up outside of the specified y domain are automatically discarded.domain
andrestrict y to domain
as settings the overall view port for the whole graph, and PGFplots will then figure out what to draw.\pgfkeysvalueof{/pgfplots/xmin}
(and analogous) in order to obtain the value ofxmin
,ymin
andymax
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.\addplot
to draw the linex=5
, I use explicit coordinates. This is mostly because I found the PGFplots behaviour to be slightly inconsistent sometimes.\addplot coordinates{-1,-1};
to draw a single point, I used one of the basic TikZ 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.width=\linewidth
so that the plot fills the width of the current line. As forheight=0.7\linewidth
, it is arbitrary (I could have usedheight=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 the0.7
in particular, I typically use0.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 used0.7
.