12

I want to show narrow segments out of a large spectrum. Since it is one spectrum, I want to use one single plot, but hide the irrelevant parts. To make clear that I show disconnected parts, I want to use discontinued axis lines between the parts. The code example shows how far I came (based on an example from the manual):

\documentclass[tikz]{standalone}

\usepackage{pgfplots}
\pgfplotsset{width=7cm,compat=1.7}

\begin{document}

\begin{tikzpicture}
  \begin{axis}[
    axis x line=bottom,
    axis x discontinuity=parallel,
    axis y line=left,
    xmin=360, xmax=600,
    ymin=0, ymax=7,
    enlargelimits=false
    ]
    \addplot coordinates {
      (420,2)
      (500,6)
      (590,4)
    };
  \end{axis}
\end{tikzpicture}

\newpage

\begin{tikzpicture}
  \begin{axis}[
    axis x line=bottom,
    axis y line=left,
    ymin=0, ymax=7,
    enlargelimits=false
    ]
    \addplot coordinates {
      (420,2)
      (500,6)
      (590,4)
    };

    \addplot coordinates {
      (25420,2)
      (25500,6)
      (25590,4)
    };

    \addplot coordinates {
      (50420,2)
      (50500,6)
      (50590,4)
    };
  \end{axis}
\end{tikzpicture}

\newpage

\begin{tikzpicture}
  \begin{axis}[
    axis x line=bottom,
    axis y line=left,
    xmin=400, xmax=1200,
    ymin=0, ymax=7,
    enlargelimits=false
    ]
    \addplot+ coordinates {
      (420,2)
      (500,6)
      (590,4)
    };
  \end{axis}

  \begin{axis}[
    axis x line=none,
    axis y line=none,
    xmin=25100, xmax=25900,
    ymin=0, ymax=7,
    enlargelimits=false
    ]
    \addplot+ coordinates {
      (25420,2)
      (25500,6)
      (25590,4)
    };
  \end{axis}

  \begin{axis}[
    axis x line=none,
    axis y line=none,
    xmin=49800, xmax=50600,
    ymin=0, ymax=7,
    enlargelimits=false
    ]
    \addplot coordinates {
      (50420,2)
      (50500,6)
      (50590,4)
    };
  \end{axis}
\end{tikzpicture}

\end{document}

The code leads to these results: Discontinuity left. Entire plot, no discontinuities. Partial plots, discontinuities not marked,

How can I discontinue the x axis and mark the discontinuities similar to the first plot, but between the parts?

Edit:

Fortunately, I was able to solve parts of the problem, but it's a very “hackish” solution:

\documentclass[tikz,convert]{standalone}

\usepackage{pgfplots}
\pgfplotsset{width=7cm,compat=1.7}
\usepgfplotslibrary{units}

\begin{document}

\begin{tikzpicture}
  \begin{axis}[
    name=a,
    width=.25\linewidth,
    height=5cm,
    axis x line=box,
    axis y line*=left,
    xmin=350, xmax=750,
    ymin=0, ymax=7,
    xticklabels={,,0.4,,,0.7},
    ]
    \addplot+ coordinates {
      (420,2)
      (500,6)
      (590,4)
    };
  \end{axis}

  \begin{axis}[
    name=b,
    width=.25\linewidth,
    height=5cm,
    xshift=2cm,
    axis x line=box,
    axis y line=none,
    xmin=25350, xmax=25750,
    ymin=0, ymax=7,
    xticklabels={,,25.4,,,25.7},
    change x base,
    x SI prefix=kilo,
    ]
    \addplot+ coordinates {
      (25420,2)
      (25500,6)
      (25590,4)
    };
  \end{axis}

  \begin{axis}[
    name=c,
    width=.25\linewidth,
    height=5cm,
    xshift=4cm,
    axis x line=box,
    axis y line*=right,
    xmin=50350, xmax=50750,
    ymin=0, ymax=7,
    xticklabels={,,50.4,,,50.7},
    yticklabel=\empty,
    scaled x ticks=base 10:-3
    ]
    \addplot+ coordinates {
      (50420,2)
      (50500,6)
      (50590,4)
    };
  \end{axis}

  \draw [dotted] (a.south east) -- (b.south west);
  \draw [dotted] (a.north east) -- (b.north west);
  \draw [dotted] (b.south east) -- (c.south west);
  \draw [dotted] (b.north east) -- (c.north west);
\end{tikzpicture}

\end{document}

Result:

Partial solution

With that solution, automatic scaling to \linewidth does not work and everything has to be done by hand, especially the line style. Is there some way to optimize and automate it?

Chris
  • 3,301
  • 2
  • 20
  • 23
  • Related: http://tex.stackexchange.com/questions/46422/axis-break-in-pgfplots and the linked ones – Qrrbrbirlbel Mar 07 '13 at 14:24
  • 1
    @ChristianFeuersänger: I've seen the other question before, but didn't consider it being a duplicate since there are already opportunities for one discontinuity in pgfplots. Now I understand better what the original discontinuity in pgfplots does and see the similarity between the questions. Anyway, thanks for the clarification that there is little chance for a better solution, especially one with only one axis statement. I'll try to improve my own solution and post updates here. – Chris Mar 11 '13 at 13:02
  • Is it possible to change the vertical scale between the different parts of the plot? – joaocandre Jul 17 '13 at 17:13
  • @joaocandre: Yes, but then you should consider additional vertical axes. Just change ymin and ymax or omit them. – Chris Jul 18 '13 at 14:41
  • Duping based on the above comments: flag if I'm wrong and I'll reopen. – Joseph Wright Aug 09 '13 at 20:43

0 Answers0