3

Why are the two lines drawn to different lengths? The slanted line should be shortened a bit - maybe by 2ex - and the vertical line should be lengthened to obtain the same height that the slanted line obtains.

How do I get the equation for the slanted line on the opposite side? The place it is now makes it look like I am labeling the curve y=(3/2)x + 5/2.

If I want a little more of the graph above the x-axis to be drawn, what should I change in the code? ymax=25 instead of ymax=15?

\documentclass{amsart}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}


\begin{document}



\begin{tikzpicture}
\begin{axis}[width=4in,axis equal image,clip=false,
    axis lines=middle,
    xmin=-15,xmax=15,
    domain=-15:15, samples=101,
    xlabel=$x$,ylabel=$y$,
    ymin=-15,ymax=15,
    restrict y to domain=-20:20,
    enlargelimits={abs=1cm},
    axis line style={latex-latex},
    ticklabel style={font=\tiny,fill=white},
    xtick={\empty},ytick={\empty}
]
\addplot[samples=251,domain=-25:1.5] {(3*x^2+5*x)/(2*x-3)};
\addplot[samples=251,domain=1.5:25] {(3*x^2+5*x)/(2*x-3)} node[above,pos=0.85]{$\scriptstyle{y}=\frac{3x^{2}+5x}{2x-3}$};
\addplot [dashed, latex-latex] {(3/2)*x+5/2} node [pos=0.15, anchor=south, font=\footnotesize, sloped] {$y=\frac{3}{2}x+\frac{5}{2}$};
\addplot [dashed, latex-latex] (1.5,x) node [pos=0.15, anchor=north, font=\footnotesize, sloped] {$x=\frac{3}{2}$};
\end{axis}
\end{tikzpicture}

\end{document}

enter image description here

  • Something like node[below] instead of above? – percusse Sep 27 '14 at 13:47
  • You can get the equation of the slanted line the way you want by changing anchor=south to anchor=north. – Sony Sep 27 '14 at 13:51
1
\documentclass{amsart}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}


\begin{document}



\begin{tikzpicture}
\begin{axis}[width=4in,axis equal image,clip=false,
    axis lines=middle,
    xmin=-15,xmax=15,
    samples=101,
    xlabel=$x$,ylabel=$y$,
    ymin=-15,ymax=15,
    restrict y to domain=-20:25,
    enlargelimits={abs=1cm},
    axis line style={latex-latex},
    ticklabel style={font=\tiny,fill=white},
    xtick={\empty},ytick={\empty},
]
\addplot[samples=251,domain=-25:1.5] {(3*x^2+5*x)/(2*x-3)};
\addplot[samples=251,domain=1.5:15] {(3*x^2+5*x)/(2*x-3)} node[above right,anchor=south west,pos=0.95]{$\scriptstyle{y}=\frac{3x^{2}+5x}{2x-3}$};
\addplot [dashed, latex-latex,domain=-13:10] {(3/2)*x+5/2} node [pos=0.15, anchor=north, font=\footnotesize, sloped] {$y=\frac{3}{2}x+\frac{5}{2}$};
\addplot [dashed, latex-latex,domain=-17:17.5] (1.5,x) node [pos=0.15, anchor=north, font=\footnotesize, sloped] {$x=\frac{3}{2}$};
\end{axis}
\end{tikzpicture}

\end{document}

enter image description here

Some explanations:

You can add the proper domain to the dashed plots. For the slanted line, let us say we fix ,domain=-13:10. Then the maximum and minimum values of y are 17.5 and -17 respectively. Noe we fix theses values for y in the vertical dashed line as domain=-17:17.5 in the coordinate {1.5,x}.

To bring the label below for the slanted line change the anchor to anchor=north,.

To extend the upper curve you have to change the values in restrict y to domain=-20:25,. Change the ymax and xmax, ymin and xmin values accordingly so as to get the axis line length suitably. (Or change the value of abs=1cm in enlargelimits).

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.