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 need to have some kind of jump on the axis of the plot in pgfplots package. Something similar to the following figure where some part of the scales are jammed.

enter image description here

It would be interesting to have even different scales for the top and botoom traces (exactly like the figure).

Any idea is appreciated.

share|improve this question

1 Answer 1

up vote 14 down vote accepted

You can simply use two axes that you position relative to each other.

Here's an example where I've defined a new key axis break gap that can be used to set the gap between the axes:

\documentclass[border=5mm]{standalone}
\usepackage{pgfplotstable}
\tikzset{
    axis break gap/.initial=1mm
}
\begin{document}
    \begin{tikzpicture}
        \begin{axis}[
            name=bottom axis,
            domain = 0:pi,
            scale only axis,
            width=8cm, height=4cm,
            axis x line*=bottom
        ]
            \addplot [smooth] {-cos(deg(x))^6/10+0.2};
            \addplot [smooth] {-cos(deg(x))^6/10+0.4};
        \end{axis}
        \begin{axis}[
            at=(bottom axis.north),
            anchor=south, yshift=\pgfkeysvalueof{/tikz/axis break gap},
            domain = 0:pi,
            scale only axis,
            width=8cm, height=4cm,
            axis x line*=top,
            xticklabel=\empty,
            after end axis/.code={
                \draw (rel axis cs:0,0) +(-2mm,-1mm) -- +(2mm,1mm)
                    ++(0pt,-\pgfkeysvalueof{/tikz/axis break gap})
                    +(-2mm,-1mm) -- +(2mm,1mm)
                    (rel axis cs:1,0) +(-2mm,-1mm) -- +(2mm,1mm)
                    ++(0pt,-\pgfkeysvalueof{/tikz/axis break gap})
                    +(-2mm,-1mm) -- +(2mm,1mm);
            }
        ]
            \addplot [smooth] {-cos(deg(x))^6+2};
            \addplot [smooth] {-cos(deg(x))^6+4};
        \end{axis}
    \end{tikzpicture}
\end{document}
share|improve this answer
    
Thanks Jake. This is exactly what I needed. –  antmw1361 Jan 24 '13 at 7:41

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.