Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

This question already has an answer here:

I want to plot a function x^3/(x^2-1) but it doesn't work.



    \draw[->] (-5,0) -- (5,0) node[right] {$x$}; 
    \draw[->] (0,-5) -- (0,5) node[above] {$y$};
    \draw [color=blue, thick] plot ({\x},{pow(\x,3)/(pow(\x,2)-1)});


It does something like this. It should be non-continuous function, not this.


How to fix it? Thanks.

share|improve this question

marked as duplicate by dustin, Heiko Oberdiek, mafp, barbara beeton, Claudio Fiandrino Aug 27 '13 at 6:08

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

The output of this are only axis and a caption. –  goLK Aug 26 '13 at 21:19
I've added a little bit of information on how to add your own labels for ticks and such to my answer. If this doesn't help feel free to ask. –  Philipp Aug 26 '13 at 23:15

1 Answer 1

up vote 17 down vote accepted

If using pgfplots would be ok for you then you could avoid such problems. Instead of the standalone class you can, of course, use any other documentclass you like.

Edit: I pimped my example a little. If you want to label some points or add function definitions etc. to your plot you can do this like in any other tikzpicture: creating nodes and drawing works in the same way as usual. To make your life easy you can access the in-plot coordinates via axis cs:, so if you want to create a node at the in-plot point x=1 and y=0 you can use something like \node at (axis cs:1,0) {$x=1$};.



        restrict y to domain=-5:5,
        xmin = -5, xmax = 5,
        ymin = -5, ymax = 5,
        unbounded coords=jump,
        axis x line=middle,
        axis y line=middle,
        x label style={
          at={(axis cs:5.02,0)},
        every axis y label/.style={
          at={(axis cs:0,5.02)},
        legend style={
          at={(axis cs:-5.2,5)},
          anchor=west, font=\scriptsize

      \addplot[color=blue, mark=none, domain=-5:5] {x^3)/((x^2) - 1)};
      \addlegendentry[blue]{$f(x)=\frac{x^3}{x^2 - 1}$}
      \draw[dashed] ({axis cs:1,0}|-{rel axis cs:0,1}) -- ({axis cs:1,0}|-{rel axis cs:0,0});
      \draw[dashed] ({axis cs:-1,0}|-{rel axis cs:0,1}) -- ({axis cs:-1,0}|-{rel axis cs:0,0});
      \node[below right, font=\scriptsize] at (axis cs:1,0) {$x=1$};
      \node[below left, font=\scriptsize] at (axis cs:-1,0) {$x=-1$};

enter image description here


Here is a pure tikz solution. It's not very elegant but in case one doesn't want to use pgfplots it might be a good starting point.



   \begin{tikzpicture}[smooth, scale=0.5]
        \draw[->] (-10,0) -- (10,0) node[right] {$x$}; 
        \draw[->] (0,-\ymax) -- (0,\ymax) node[above] {$y$};
        \draw [color=blue, thick, domain=-10:-1.05, samples=200] plot ({\x},{pow(\x,3)/(pow(\x,2)-1)});
        \draw [color=blue, thick, domain=-0.96:0.96, samples=200] plot ({\x},{pow(\x,3)/(pow(\x,2)-1)});
        \draw [color=blue, thick, domain=1.05:10, samples=200] plot ({\x},{pow(\x,3)/(pow(\x,2)-1)});
        \draw [color=black, dashed] (-1, -\ymax) -- (-1, \ymax);
        \draw [color=black, dashed] (1, -\ymax) -- (1, \ymax);



enter image description here

share|improve this answer
Thanks for your reply but I use my documentclass and I also need similar looking graphs. –  goLK Aug 26 '13 at 21:22
@goLK here is just using the standalone class to generate the image. The image wont be affected if you use the article class instead. You can always remove the x and y tick marks and add y and x if that is what you mean by similar looking. –  dustin Aug 26 '13 at 21:27
@goLK I improved the look of my example a little. Is your problem with the documentclass solved by dustin's comment? –  Philipp Aug 26 '13 at 21:49
Thanks but "! Package tikz Error: Unknown coordinate system 'ticklabel*'.". –  goLK Aug 26 '13 at 21:55
@goLK Strange, for me it's compiling fine. Have you tried compiling just my example or does the problem arise in your real document? –  Philipp Aug 26 '13 at 21:59

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