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 make a y-axis discontinuity, but I also need to configure enlargelimits=true. The problem is that the axis is not showing correctly, as the below picture show. If I set enlargelimits=false, then the axis discontinuity is correctly done, but the axis values are messed up, as the above picture shows. How can I fix my plots?

enter image description here

Here is the MWE of the picture:

\documentclass{article}
\usepackage{pgfplots}
\usepackage{caption}
\begin{document}

\begin{figure}[H]
\begin{center}
\begin{tikzpicture}
\begin{axis}[
axis x line=bottom,
axis y line=left,
tick align=outside,
axis y discontinuity=crunch, enlargelimits=false
,xtick=data, xlabel=balbalbala, ymin=60, ylabel={balbal [\%]},xlabel style={yshift=-0.3cm}, clip=false, ymax=100]
\addplot[smooth,mark=*,blue] coordinates {
(1,68.21)
(2,78.14)
(3,73.57)
(4,87.7)
(5,85.47)
(6,87.36)
(7,89.1)
(8,96.1)
(9,95.7)
(10,91.4)
(11,84.9)
(12,79.69)
};
\node[coordinate,pin=above left:{96.1\%}] at (axis cs:8,96.1) {};
\end{axis}
\end{tikzpicture}
\captionsetup{justification=centering}
\caption[asdf]{RBlalalalala}
\label{lalalala}
\vspace{1cm}
\begin{tikzpicture}
\begin{axis}[
axis x line=bottom,
axis y line=left,
tick align=outside,
axis y discontinuity=crunch, enlargelimits=true
,xtick=data, xlabel=blablablabla, ymin=400, ymax=1000, clip=false, ylabel=balbal, xlabel style={yshift=-0.3cm}, ylabel style={yshift=0.3cm}]
\addplot[smooth,color=red,mark=x]
coordinates {
(1,944.89)
(2,822.57)
(3,815.4)
(4,707.97)
(5,597.45)
(6,600.83)
(7,568.89)
(8,526.42)
(9,539.7)
(10,573.76)
(11,694.94)
(12,795.55)
};
\end{axis}
\end{tikzpicture}
\captionsetup{justification=centering}
\caption[balbla]{balbalbalblablablalbalb}
\label{balbaba}
\end{center}
\end{figure}

\end{document}
share|improve this question

2 Answers 2

up vote 3 down vote accepted

It seems, as if this is not possible. All examples for discontinuities in the pgf manual are using the option \enlargelimits=false. However, you can just do it manually. \enlargelimits=true increases the limits by 10 % to both sides, so just use xmin and xmax to specify what ever you need.

Some notes:

  • If you leave xtick=data away, it looks much better (imho).

  • the default for \enlargelimits= is true. However, the result looks the same when you comment this option. Looks a bit like a bug to me or I am not seeing some documentation...

  • I would recommend to insert a \end{figure}\begin{figure}\centering between the two figures or to use the package subcaption in order to nicely set two images in one float.

--

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.10}
\usepackage{siunitx}

\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}
\begin{axis}[%
,axis x line=bottom,
,axis y line=left,
,tick align=outside,
,axis y discontinuity=crunch
,xmin=0
,xmax=13
,ymin=60
,ymax=100
,enlargelimits=false
%,xtick=data % more beautiful perhaps
,xlabel=balbalbala
,ytickmin=70
,ylabel={balbal in \%}
%,xlabel style={yshift=-0.3cm} % just if you really want it. I would leave it away.
,clip=false
]
\addplot[smooth,mark=*,blue] coordinates {%
(1,68.21)
(2,78.14)
(3,73.57)
(4,87.7)
(5,85.47)
(6,87.36)
(7,89.1)
(8,96.1)
(9,95.7)
(10,91.4)
(11,84.9)
(12,79.69)
};
\node[coordinate,pin=above left:{\SI{96.1}{\percent}}] at (axis cs:8,96.1) {};
\end{axis}
\end{tikzpicture}
\caption{RBlalalalala}
\label{lalalala}
%\vspace{1cm} % just if you really want it. I would leave it away.
\begin{tikzpicture}
\begin{axis}[%
,axis x line=bottom,
,axis y line=left,
,tick align=outside,
,axis y discontinuity=crunch
,xmin=0
,xmax=13 %enlargelimits=true
,ymin=400
,ymax=1000
,xtick=data
,xlabel=blablablabla
,ytickmin=500
%,clip=false % not needed here
,ylabel=balbal
%,xlabel style={yshift=-0.3cm} % just if you really want it. I would leave it away.
%,ylabel style={yshift=0.3cm} % just if you really want it. I would leave it away.
]
\addplot[smooth,color=red,mark=x] coordinates {%
(1,944.89)
(2,822.57)
(3,815.4)
(4,707.97)
(5,597.45)
(6,600.83)
(7,568.89)
(8,526.42)
(9,539.7)
(10,573.76)
(11,694.94)
(12,795.55)
};
\end{axis}
\end{tikzpicture}
\caption{balbalbalblablablalbalb}
\label{balbaba}
\end{figure}
\end{document}

enter image description here

I also corrected:

  • begin{center} to \centering

  • \pgfplotsset{compat=1.10} as requested in the warnings

  • \ymintick in order to set the first tick above the crunshing.

share|improve this answer
    
Thank you! And it's possible to draw the last value of the y axis below the arrow? –  user54782 Jun 20 at 12:08
    
Which version of the two above do you prefer? Do you want the twelve below the arrow xmax=12 or the 13? –  LaRiFaRi Jun 20 at 12:16
    
I'm not sure if I understood you, I would like to have the 100 value tick below the arrow head in the y axis (in the first plot). Thanks! –  user54782 Jun 20 at 12:26
    
ymax=103 looks nice to me. Or instead enlarge y limits=upper as suggested by @percusse –  LaRiFaRi Jun 20 at 12:29

You can enlarge only the upper limit of the y axis via enlarge y limits={upper} which would use the default value. If that's not enough then you can also add more via value key, e.g., if I replace the

enlargelimits=false

with

enlarge y limits={value=0.5,upper}

I get

enter image description here

share|improve this answer

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.