# Dimension too large in pgf plot

I am trying to create a pgf plot which includes (among others) a constant function f(x)=1. My x-axis should be restricted to some range (see below), and there is also a restriction on the y-axis. This is the minimal code that reproduces the issue:

\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xmin=0,
xmax=.1,
ymin=0,
ymax=2]
\end{axis}
\end{tikzpicture}
\end{document}


This code produces the error

LaTeX Font Info:    External font cmex10' loaded for size
(Font)         <7> on input line 11.
LaTeX Font Info:    External font cmex10' loaded for size
(Font)         <5> on input line 11.
! Dimension too large.

l.11           \end{axis}

I can't work with sizes bigger than about 19 feet.
Continue and I'll use the largest value I can.
! Dimension too large.


The last seven lines of the error message repeat 5 times. This happens no matter what values I use for the ymin and ymax parameters, but only for certain xmin and xmax. From trying different values, my guess would be that xmin-xmax has to be greater than approximately 0.15 for LaTeX to compile this successfully, but in my use case it has to be a range from xmin=.0005 to xmax=.0027.

Why does LaTeX throw an error when the range is too small (or is there something else wrong with my code)?

~ \$ pdflatex -version
pdfTeX 3.1415926-2.5-1.40.14 (TeX Live 2013/Debian)

-

You need to tell pgfplots that you are plotting an expression, and give it a domain:

 \addplot expression[domain=0:1]{1};


% arara: pdflatex
\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xmin=0,
xmax=.1,
ymin=0,
ymax=2]

Thank you, this solved the problem for me. I had to use the values 0:0.01 because of the x values I was using. Is there a reason why LaTeX can draw this expression without being told a domain if the difference of the values of xmin and xmax is large enough, but fails otherwise? –  pascalhein Mar 7 '14 at 17:54
According to the manual, expression is implied in the absence of any other input type. –  Paul Gessler Mar 7 '14 at 17:55
@PaulGessler indeed, but compare the output from \addplot [domain=0:1]{1}; and \addplot expression[domain=0:1]{1}; –  cmhughes Mar 7 '14 at 18:07
Interesting---the difference I see is that the style black is applied in the case where expression is left out. Is this documented? –  Paul Gessler Mar 7 '14 at 18:12