1

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 [dashed] {tan(x)};
\addplot [restrict y to domain=-7:7,line width=1pt] {tan(x)};
\end{axis}
\end{tikzpicture}

\end{document}
2

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 [dashed] {tan(x)};
\addplot [restrict y to domain=-7:7,line width=1pt] {tan(x)};
\end{axis}
\end{tikzpicture}

\end{document}

enter image description here

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.