i'm using tikzpicture and pgfplots to make my plots and i'm currently facing a problem when i use a function like 2/x

    \begin{axis}[ ymin=-10, ymax=10, xmin=-10, xmax=10, axis lines=middle, xlabel = $x$ , ylabel = $y$]
        \addplot[dashed, color=red]{ (2)/(x) };

It gives me multiple errors like: dimension too large and arithmetic overflow, anyone knows how to fix it?

  • 1
    you must restrict the domain to avoid that you divide by zero (or nearly zero). See section 4.22 Skipping Or Changing Coordinates in the pgfplots documentation. Oct 19, 2022 at 14:09

1 Answer 1


You need to 'jump' over the singularity in x=0 whit 2 domains:

\addplot[dashed, color=red,domain =-10:-.1]{ (2)/(x) };
\addplot[dashed, color=red,domain =0.1:10]{ (2)/(x) };

So the output is:

enter image description here

You must log in to answer this question.

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