[Tex/LaTex] Axis discontinuity + enlargelimits not showing axis correctly in pgfplots

pgfplots

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}

Best Answer

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.