# Axis break in pgfplots

Is there an easy way to 'break' the axis in a pgfplots environment? What I'm talking about is something like this

Any minimal plot will do as an example...for example

\documentclass{minimal}
\usepackage{tikz}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
\begin{axis}[ymin=0, ymax=80]
\end{axis}
\end{tikzpicture}

\end{document}


For example, in the below plot,

I want to break the axis from around y = 10 to y = 40.

Any ideas? Does PGF have this functionality? A search for break' in the manual doesn't yield anything.

-
You can search for axis y discontinuity in the pgfplots manual. –  percusse Mar 1 '12 at 23:03
The axis y discontinuity option won't let you plot values near the origin, it is only meant for showing that a plot doesn't start near zero. TSGM, could you provide a more concrete example of what you want to achieve? A break in a column plot is much easier than in a line plot. –  Jake Mar 1 '12 at 23:10
@Jake: I've edited the original post to be more specific for what kind of break I want to achieve. –  TSGM Mar 1 '12 at 23:19

One solution for the posted minimal example could be the following:

\documentclass{minimal}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{pgfplots.groupplots}

\begin{document}
\pgfplotsset{
% override style for non-boxed plots
% which is the case for both sub-plots
every non boxed x axis/.style={}
}
\begin{tikzpicture}
\begin{groupplot}[
group style={
group name=my fancy plots,
group size=1 by 2,
xticklabels at=edge bottom,
vertical sep=0pt
},
width=8.5cm,
xmin=-6, xmax=6
]

\nextgroupplot[ymin=45,ymax=80,
ytick={60,80},
axis x line=top,
axis y discontinuity=parallel,
height=4.5cm]

\nextgroupplot[ymin=0,ymax=5,
ytick={0},
axis x line=bottom,
height=2.0cm]
\end{groupplot}
\end{tikzpicture}

\end{document}


It combines two plots in a groupplot-environment and plots them on top of each other. Using the axis y discontinuity is possible then:

-
Ah yes, that's very clever! Would you mind adding a sentence or two describing the approach? –  Jake Jul 9 '12 at 22:58
The basic idea is to disable the "boxed" style when gluing two group plots together while setting vertical sep to 0. Then you can define individual axis x line for the upper and lower plot which results in the whole groupplot appearing as one box. –  Michi Jul 11 '12 at 10:15

Is there an easy way ...

The only "easy" ways to accomplish axis discontinuities are the axis y discontinuity feature mentioned by percusse - which is unavailable for your specific use-case.

Your use-case would need a much more sophisticated implementation which

• maps coordinates
• draws discontinuity markers at the correct places into the axis
• knows how to draw such markers into each bar (and knows how to draw it for other plot handlers as well).

In short: the feature is unavailable. You can post a feature request on sourceforge.

If you are a power-user, you could consider implementing the first two steps using a custom coordinate transformation and some decoration for the axis.

-
Follow up, is there any guru who can solve this problem? –  user14024 Apr 28 '12 at 1:29
Plus one with Nadim's request –  Rave May 28 '12 at 16:08
I also need to accomplish something like this. My use case is nearly identical to the excel image in the OP. –  Trevor Aug 20 '12 at 23:14
Nice feature request. I would need it myself. –  Pygmalion Aug 27 '12 at 15:28
There is another problem: if using scaled ticks, say scaled y ticks=base 10:2`, I get an annoying 10^{-2} on both y axes. –  Francisco Dec 3 '12 at 19:42