# Dimension too large error - tan graph

by A. Goodier   Last Updated May 15, 2019 21:23 PM

I have put a restriction on the y values but I still get a dimension too large' error. Can anyone suggest how to prevent the error?

\documentclass[12pt]{article}
\usepackage{amsmath,amsthm,amssymb,amsfonts}
\usepackage{graphicx,float,wrapfig}
\usepackage{array}
\usepackage{microtype}
\usepackage{tikz,pgfplots}
\usetikzlibrary{calc}
\usetikzlibrary{math}
\begin{document}

\begin{tikzpicture}[scale=1.3]
\begin{axis}[
ymin=-7,ymax=7,
xmin=-1,xmax=361,
axis lines=center,
xtick={0,45,90,...,360},
domain=-1:361,
samples=1000]
\addplot [restrict y to domain=-7:7,line width=1pt] {tan(x)};
\end{axis}
\end{tikzpicture}

\end{document}

Tags :

The problem goes away if you increase the samples by 1. This is because this avoids to have a sample too close to a singularity. Of course, the question is whether you really need that many samples, but in this answer I assume you do. Not also that you should pass the scale=1.3 to the axis, not to the tikzpicture if you plan on using fillbetween, say. And it is always better to specify the version (and I took the liberty to remove some unrelated packages.)

\documentclass[12pt]{article}
\usepackage{microtype}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\usetikzlibrary{calc}
\usetikzlibrary{math}
\begin{document}

\begin{tikzpicture}
\begin{axis}[scale=1.3,
ymin=-7,ymax=7,
xmin=-1,xmax=361,
axis lines=center,
xtick={0,45,90,...,360},
domain=-1:361,
samples=1001]
\addplot [restrict y to domain=-7:7,line width=1pt] {tan(x)};
\end{axis}
\end{tikzpicture}

\end{document}
`

marmot
May 15, 2019 20:56 PM

## Related Questions

Updated April 14, 2017 04:23 AM

Updated June 14, 2018 09:23 AM

Updated March 17, 2019 19:23 PM

Updated August 07, 2017 17:23 PM

Updated June 19, 2019 02:23 AM