2

I would like to graph the function $y = \sqrt{x^{2} - 4}/\sqrt{x - 2}$ on the domain from -5 to 30. This function will be Sy = \sqrt{x + 2}$ restricted to the open interval $(2, \infty)$. So, I would like an open circle at (2,0). Now, a horizontal grid line is passing through it, and the graph of the function is passing through it.

I would like a dashed line drawn down to the x-axis from (2,0), and a tick mark there and below it the label "2." I would also like a tick mark below the x-intercept and below it the label "-2."

\documentclass[10pt]{amsart}
\usepackage{tikz}
\usetikzlibrary{calc,angles,positioning,intersections,quotes,decorations.markings}
\usetkzobj{all}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}

\begin{document}

    \begin{tikzpicture}
\begin{axis}[grid=both,
          xmax=41,ymax=6,
          axis lines=middle,
          restrict y to domain=-1.5:6.5,
          enlargelimits,
          axis line style={shorten >=-0.25cm,shorten <=-0.25cm,latex-latex},
          ticklabel style={fill=white}]
\addplot[domain=2:36,mark=none,samples=200] {sqrt(x + 2)} node[fill=white, below]{$y=\frac{x^{2} - 4}{\sqrt{x-2}}$};
\addplot[domain=-2:2,dashed,mark=none,samples=200] {sqrt(x + 2)};
\draw (axis cs:2,2) circle [radius=1.5pt];
\end{axis}
\end{tikzpicture}

\end{document}
2

To get an extra tick mark at specified coordinates without adding grid lines, use

      extra x ticks={-2,2},
      extra x tick style={grid=none}

To fill the circle with white, use

fill=white

To get a vertical dashed line from (2,2) to (2,0), use

\draw [dashed] (2,2) -- (2,0);

(no need for axis cs: if you're using \pgfplotsset{compat=1.11} or higher).

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

\begin{document}

\begin{tikzpicture}
\begin{axis}[grid=both,
          xmax=41,ymax=6,
          axis lines=middle,
          restrict y to domain=-1.5:6.5,
          enlargelimits,
          axis line style={shorten >=-0.25cm,shorten <=-0.25cm,latex-latex},
          ticklabel style={fill=white},
          extra x ticks={-2,2},
          extra x tick style={grid=none}
]
\addplot[domain=2:36,mark=none,samples=200] {sqrt(x + 2)} node[fill=white, below]{$y=\frac{x^{2} - 4}{\sqrt{x-2}}$};
\addplot[domain=-2:2,dashed,mark=none,samples=200] {sqrt(x + 2)};

\draw [densely dashed] (2,2) -- (2,0);
\draw [fill=white] (2,2) circle [radius=1.5pt];
\end{axis}
\end{tikzpicture}

\end{document}
  • Except for two adjustments, this is the graph for which I was asking. It does not look like a horizontal shift of the square root function because the scaling of the y-axis is different from that of the x-axis. What code will make the scales of the two axes the same? Why isn't the label for the graph put below the graph? It is covering part of the graph. – user143462 Sep 16 '14 at 19:08
  • I would like the length of the x-axis to be doubled. I do not know how to instruct TikZ how wide or how high the axes are to be drawn. – user143462 Sep 16 '14 at 19:11
  • @user143462: The label is placed directly below the end of the graph, as instructed. You can move it down further by setting below=3ex, for example, or you can place it above the plot by using above and adding clip=false to the axis options. For the other additional questions, please consult the PGFPlots manual (hint: the necessary options are described in section 4.10 "Scaling options"). – Jake Sep 16 '14 at 19:19
  • I added the command "\def\axisdefaultwidth{6.25in}" to get a wider graph. I am looking on page 238 at the web site "pgfplots.sourceforge.net/pgfplots.pdf" for scaling. I do not know the code to get the same scaling for the two axes. I do not know what the manual is saying about "/pgfplots/height{<dimem>}" and "/pgfplots/scale only axis=true". I would appreciate it if you can give me the code to get the same scaling. – user143462 Sep 16 '14 at 20:36
  • 1
    @user143462: To get the same scaling for both axes while keeping the width and height unchanged, set axis equal. To get the same scaling for both axes and make the plot take up only the space needed to accommodate the axis limits, set axis equal image. To change the width or height, set width=<...> or height=<...>. – Jake Sep 16 '14 at 20:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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