14

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.

17

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}
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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