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?
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 usexmin
andxmax
to specify what ever you need.Some notes:
If you leave
xtick=data
away, it looks much better (imho).the default for
\enlargelimits=
istrue
. 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 packagesubcaption
in order to nicely set two images in onefloat
.--
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.