4

I want to graph a function with rather large values using the pgfplots package. The function is represented as (1375*(801-2.96*x)/(x*(18-0.1*x).

The code I have currently is:

\begin{tikzpicture}
\begin{axis}[ xlabel={$x$}, ylabel={$C$}
,samples=200, grid, thick
,xmin=0, xmax=200, ymin=0, ymax=2000
,legend pos=outer north east
]
\addplot+[no marks] {(1375*(801-2.96*x)/(x*(18-0.1*x)};
\addlegendentry{$C(x)$} 
\end{axis}
\end{tikzpicture}

When I try to render the PDF, it generates an error:

"! Dimension too large.<recently read> \pgf@yy \end{axis}"

1 Answer 1

9

Welcome to TeX-SE! The problem can be removed by specifying the domain and making ymax larger. (I also added unbounded coords=jump.)

\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{tikzpicture}
\begin{axis}[ xlabel={$x$}, ylabel={$C$}
,samples=200, grid, thick,unbounded coords=jump,
,xmin=0,xmax=200, ymin=0,ymax=20000,
,legend pos=outer north east
]
\addplot+[no marks,domain=0:200] {(1375*(801-2.96*x)/(x*(18-0.1*x))};
\addlegendentry{$C(x)$} 
\end{axis}
\end{tikzpicture}
\end{document}

enter image description here

Even ymax=2300 works but this cuts away most of the plot.

\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{tikzpicture}
\begin{axis}[ xlabel={$x$}, ylabel={$C$}
,samples=200, grid, thick,unbounded coords=jump,
,xmin=0,xmax=200, ymin=0,ymax=2300,
,legend pos=outer north east
]
\addplot+[no marks,domain=0:200] {(1375*(801-2.96*x)/(x*(18-0.1*x))};
\addlegendentry{$C(x)$} 
\end{axis}
\end{tikzpicture}
\end{document}

enter image description here

You can retain your ymax using restrict y to domain=0:2000 but the result is not great because some stretches will be cut away.

\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{tikzpicture}
\begin{axis}[ xlabel={$x$}, ylabel={$C$}
,samples=501, grid, thick,unbounded coords=jump,
,xmin=0,xmax=200, ymin=0,ymax=2000,
,legend pos=outer north east
]
\addplot+[no marks,domain=0:200,restrict y to domain=0:2000] {(1375*(801-2.96*x)/(x*(18-0.1*x))};
\addlegendentry{$C(x)$} 
\end{axis}
\end{tikzpicture}
\end{document}

enter image description here

You must log in to answer this question.

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