How to Make a Broken Y-Axis in PGFPlots
At a glance
- 1. Choose two ranges
Decide which lower and upper y-values the two plot panels should show.
- 2. Stack two axes
Use PGFPlots groupplots to align two axes vertically with a small gap.
- 3. Match x settings
Give both panels the same x limits, width, and tick positions.
- 4. Repeat the plot
Add the same data to both panels; each y range displays its own part.
A broken y-axis shows two separated ranges of values while leaving out the interval between them. PGFPlots can do this by stacking two axes: the lower panel shows one y-range, and the upper panel shows another. This is a practical way to emphasize variation in data that would otherwise be hard to see on one continuous scale.
The example below uses the ranges 0–10 and 80–100. Both panels use the same x-range and plot the same points, so their horizontal positions line up.
Stack two axes with different y-limits
The groupplots library arranges multiple axes in a grid. Setting the group to one column and two rows stacks the panels. The small vertical separation creates a visible break.
\documentclass{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{groupplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
\begin{groupplot}[
group style={group size=1 by 2, vertical sep=4mm},
width=10cm,
height=3cm,
xmin=0,
xmax=5,
xtick={0,1,2,3,4,5},
]
\nextgroupplot[
ymin=80,
ymax=100,
axis x line=none,
xtick=\empty,
ylabel={Value},
]
\addplot+[only marks, mark=*] coordinates {
(0,3) (1,8) (2,92) (3,97) (4,6) (5,9)
};
\nextgroupplot[
ymin=0,
ymax=10,
xlabel={Time},
]
\addplot+[only marks, mark=*] coordinates {
(0,3) (1,8) (2,92) (3,97) (4,6) (5,9)
};
\end{groupplot}
\end{tikzpicture}
\end{document}
This complete example needs the pgfplots package and its groupplots library. The first \nextgroupplot sets the upper panel’s y-range to 80–100; the second sets the lower panel’s range to 0–10. The identical data coordinates are deliberately repeated. Each panel displays the points that fall within its own y-range, and the shared x-limits keep their horizontal positions consistent.
height sets the height of each panel, not the combined height. Adjust it and width to suit the figure. The upper panel hides its x-axis line and ticks with axis x line=none and xtick=\empty; the lower panel supplies the x-axis label.
Make the break clear
The 4 mm gap separates the panels, but it does not indicate exactly how much y-range is omitted. If that distinction matters, add diagonal break marks at the edges of the panels or annotate the omitted interval. Make sure readers can tell that the y-scale is discontinuous; otherwise they may assume the gap represents ordinary spacing on a continuous scale.
The two ranges do not need to be the same size. For example, the lower panel could cover 0–5 while the upper panel covers 50–100. Choose limits and tick marks that make the shown values easy to read, and label the panels or break if the omitted interval is not obvious.
If you want one continuous axis with custom ticks
A broken axis is different from simply choosing where y-axis tick marks appear. If your goal is to show fewer ticks without omitting any values, keep one axis and set its ticks explicitly, for example with ytick={0,20,40,60,80,100}. With a true break, the distance between the panels does not represent the omitted values, so the graph should make that discontinuity visible.
Common mistakes
- Using different x-limits: The panels will not represent the same horizontal positions. Set the same
xminandxmaxin the group options or in both panels. - Plotting data in only one panel: The other panel will be empty. Add each plot to both axes so each range can display the data that falls within it.
- Expecting the gap to adjust the scale: The space between panels is visual separation, not a numerical interval. Pick the two y-ranges explicitly with
yminandymax. - Connecting data across the omitted interval without checking the result: A line may be clipped at a panel boundary, which can make it appear to start or end there. Inspect the clipped segments carefully, or use marks when you want to show individual observations without implying a continuous path.
References
Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.