Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

What I have

What I want

\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]
      \addplot[very thick,draw=blue!70, mark=*,mark options={color=blue!70}]  coordinates
      {(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]
      \addplot[very thick,draw=red!70] expression[domain=229:1406902] {x};
      \addplot[draw=none,mark=*,mark options={color=red!70}]  coordinates
      {(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).

share|improve this question

1 Answer 1

up vote 8 down vote accepted

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]
      \addplot[very thick,draw=blue!70, mark=*,mark options={color=blue!70}]  coordinates
      {(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]
      \addplot[very thick,draw=red!70] expression[domain=229:1406902] {x} 
    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)$);
      \addplot[draw=none,mark=*,mark options={color=red!70}]  coordinates
      {(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}

enter image description here

share|improve this answer
    
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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.