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.

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

enter image description here

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]
\addplot {x*0}; 
\addplot {x^2+50};
\end{axis}
\end{tikzpicture}

\end{document}

For example, in the below plot,

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.

share|improve this question
1  
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

2 Answers 2

up vote 32 down vote accepted

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]
\addplot {x*0};     
\addplot {x^2+50};         

\nextgroupplot[ymin=0,ymax=5,
               ytick={0},
               axis x line=bottom,
               height=2.0cm]
\addplot {x*0}; 
\addplot {x^2+50};                 
\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:

Two plots using axis y discontinuity for the upper.

share|improve this answer
    
Ah yes, that's very clever! Would you mind adding a sentence or two describing the approach? –  Jake Jul 9 '12 at 22:58
1  
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.

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

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.