0

I would like the code that instructs TikZ to plot the asymptotes to the graph for the rational function y=(x^{2})/(x^{2}-9). What is the code for plotting these lines as a dashed lines with arrowheads? These should be a little shorter than the axes. The labels x=-3 and x=3 are to be typeset on the vertical asymptotes. Preferably, they would be typeset towards the bottom arrowheads, going upwards. (How do I label the axes? y is to be typeset to the right and above the top arrowhead on the y-axis, and x is to be typeset to the right and below the right arrowhead on the x-axis.)

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

\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{amsthm}

\begin{document}

\begin{tikzpicture}
\begin{axis}[width=4in,axis equal image,
    axis lines=middle,
    xmin=-15,xmax=15,
    ymin=-5,ymax=5,
    restrict y to domain=-10:10,
    enlargelimits={abs=1cm},
    axis line style={latex-latex},
    ticklabel style={font=\tiny,fill=white},
    ytick={-2},xtick={-2}
]
\addplot[samples=250,domain=-15:15] {(x^2)/(x^2-9)};
\draw[dashed,latex-latex] ({{1,0}}|-{{axis description cs:1,1}})
                       -- ({{1,0}}|-{{axis description cs:1,0}});
\end{axis}
\end{tikzpicture}


\end{document}
5
  • Screenshot please.... Sep 25, 2014 at 16:26
  • Where did you get this code from? It seems as if you did not make any attempt to change it at all. First try changing (x+2)/(x-1) to your desired function ((x)^2)/((x)^2)-9) and change the domain as desired. You can add shorten <=1.0ex, , shorten >=1.0ex option to to the dashed line to get them shorter than the axis. Sep 25, 2014 at 16:33
  • 2
    @user60254: A lot of your recent questions consist of a long PGFplots example where you list lots of small things which you would like changed. I'd recommend taking a look at the PGFplots manual and really trying to understand the code instead of having others modify it for you.
    – Fritz
    Sep 25, 2014 at 16:43
  • I have spent hours looking at this manual. It takes several minutes to Look for each instance of a word. Can you tell me the page that describes the option shorten<=1ex, shorten>=1ex and the page I can find to label the vertical asymptotes x=-3 and x=3 oging upwards?
    – user60254
    Sep 25, 2014 at 16:49
  • If you just want to look up words, there is an index at the very end of the manual. For the rest of your questions, have a look at my answer.
    – Fritz
    Sep 25, 2014 at 17:01

1 Answer 1

2

For labeling the axes, look at the section about axis labels (section 4.9.3 in my version). You probably want something like xlabel=$x$ and ylabel=$y$ in your axis options.

For labeling the asymptotes, you can place a node[left] {-3} after the coordinates in the \draw[dashed] command:

\draw[dashed,latex-latex] ({{1,0}}|-{{axis description cs:1,1}})
                       -- ({{1,0}}|-{{axis description cs:1,0}})
                          node[left] {-3};

Finally, shorten > and shorten < are TikZ options, which shorten the end and the start of a line, respectively, by the specified length. Simply add them to the options of the \draw command.

4
  • I used the commands xlabel=$x$,ylabel=$y$ in the options for the axis. The "x" is placed above the right arrowhead and the "y" is placed to the right of the top arrowhead - and on top of both the graph and the vertical line x=1. I used the command /pgfplots/xlabel shift={10pt}; after the axis options, as described on pages 200 and 201 - in 4.9 of the manual. Nothing happened. I would like to place the "x" below and to the right of the right arrowhead on the x-axis, and I would like to place the "y" above and to the right of the right arrowhead on the y-axis.
    – user143462
    Sep 25, 2014 at 18:02
  • @user143462: Sorry for not replying. I didn't get a notification because you forgot to add @Fritz at the beginning of your comment. I don't know why the ylabel shift doesn't work -- maybe it has to to with axis lines=middle. But actually, this comment would make an excellent question! Just add a small MWE containing only an empty axis and the labels, and you're good to go.
    – Fritz
    Sep 26, 2014 at 7:07
  • I was told that making a comment to a user's post would prompt tex.stackexchange to inform that user that I had made a comment. I guess that I will be in the habit of adding "@user" to my post. I just replied to Harish Kumar about my question. (I didn't enter "@Harish Kumar" to my comment. I guess that I should make another comment to inform him of my previous comment. It sounds ridiculous. Doesn't it?) Please take a look at it. I am trying to make a few graphs for a file that I need to send to my Calculus class. Only properly displaying these graphs is delaying me.
    – user143462
    Sep 26, 2014 at 13:21
  • Yes, that does indeed sound ridiculous -- I don't quite understand the rules myself. Specifically I should get a notification for all comments on my answers according to meta.stackexchange.com/questions/125208. For positioning you should look at this answer, which demonstrates the necessary technique: tex.stackexchange.com/a/122766/12440. You just have to change the anchor and set the at to 1.00 instead of 1.05.
    – Fritz
    Sep 26, 2014 at 13:47

You must log in to answer this question.

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