# Draw outside axis with pgfplots

I have the following diagram, and would like to extend the red line so it crosses the axes and goes on for a bit at the start and the end like in the second picture, but I would like the red and blue dots to still align vertically. Also, the prolongated red line should terminate above the top axis.

\documentclass{article}
\usepackage{pgf}
\usepackage{tikz}
\usepackage{pgfplots}

\begin{document}

\begin{figure} [tb]%
\centering
\begin{tikzpicture}
\begin{semilogxaxis}[
enlarge y limits=true,
enlarge x limits=false]
{(229,62) (1475,122) (23598,255) (27101,272) (32427,280) (55124,322) (758667,5509) (1273808,5649) (1406902,6375)};
\end{semilogxaxis}
\begin{semilogxaxis}[
smooth,
axis y line=none,
axis x line=none,
ticks=none,
enlarge y limits=true,
enlarge x limits=false]
{(229,229) (1475,1475) (23598,23598) (27101,27101) (32427,32427) (55124,55124) (758667,758667) (1273808,1273808) (1406902,1406902)};
\end{semilogxaxis}
\end{tikzpicture}
\caption{Caption}
\end{figure}
\end{document}


I have tried changing the width and height of the second semilogaxis, and changing the domain of the curve inside, but then I can't get the dots to align vertically.

I have also tried to use a \draw[domain=0:2000000,smooth,variable=\x] plot (axis cs:\x,\x);, but then I get a Dimension too large error, and I can't manage to make tikz's \draw plot use the FPU (Floating Point Unit).

-

You can keep drawing after plot and utilize the special coordinates current plot end/begin. By placing dummy coordinates very close to the end and the beginning, you can immitate a tangent approximation. But you have to turn off the clipping behavior of the axes. See Change linestyle within a plot to add dashed trendline? for a similar solution with a node shape which might be better in certain cases if the plot is not too funky.

\documentclass{article}
%\usepackage{pgf}
%\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{calc}
\begin{document}

\begin{figure} [tb]%
\centering
\begin{tikzpicture}
\begin{semilogxaxis}[
enlarge y limits=true,clip=false,
enlarge x limits=false]
{(229,62) (1475,122) (23598,255) (27101,272) (32427,280) (55124,322) (758667,5509) (1273808,5649) (1406902,6375)};
\end{semilogxaxis}
\begin{semilogxaxis}[
smooth,clip=false,
axis y line=none,
axis x line=none,
ticks=none,
enlarge y limits=true,
enlarge x limits=false]
coordinate [pos=0.98] (c2) coordinate [pos=0.01] (c3) (current plot end) -- ($(c2)!10!(current plot end)$)
(current plot begin) -- ($(c3)!1.2!(current plot begin)$);

Thanks! I didn't know about clip=false. I used clip=false, xmax=1406902 in the second semilogxaxis and changed the domain of the curve and that was enough. It's simpler and more accurate than empirically measuring the derivative of the curve, though it allows to show the linear interpolation of a more complex curve, and it's definitely a great idea. –  Georges Dupéron Sep 2 '12 at 16:42
Erratum: I used clip=false, xmin=229, xmax=1406902, not just clip and xmax, otherwise of course the curve isn't prolongated at leftwards. –  Georges Dupéron Sep 2 '12 at 16:51