File Exchange

image thumbnail

Break X Axis

version 1.2.0.0 (22.1 KB) by Peter
Splits the x-axis into 2 disjoint regions in order to hide an uninteresting portion of a figure.

90 Downloads

Updated 06 Aug 2013

View License

Features
1.) Minimal fuss, just works
2.) Professional looking graphs
3.) Works with all 2D graphics objects: Lines, Text, Patches, Images, etc.
5.) Obeys ‘XTickMode’ for automatic or manual positioning of tick marks.
6.) Obeys ‘Layer’ property
7.) Works with semilogy plots and with either axis reversed
8.) Can resize after splitting axis
8.) Possible to unsplit axis

Limitations
1.) No support for semilogx or loglog plots
2.) Creates extra copies of the data which may be problematic when displaying very large data sets.
3.) Text inside an axes must have 'Clipping' turned 'Off' or be added after splitting the axis. Otherwise it may be rendered twice. See TextExample.m for more details.

Cite As

Peter (2020). Break X Axis (https://www.mathworks.com/matlabcentral/fileexchange/42905-break-x-axis), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (42)

Good stuff... modified it so the break is more discrete... but there are some issues with Xlabels and the legend also fixable, also fixed an issue using print command which painted the patch black.

BAHO baho

To solve the lack of legend and it being greyed out in the previous fix:
- select any line on the plot
- enter "legend;" to create a new legend (will have same properties as original I believe)
- right-click -> color... to restore to white background.
Sorry this isn't a script-based fix, but it works.

JWall

This is a great function and much better than the other options for doing this! One problem - I can no longer get the resulting breakaxes to behave properly with the command "axis square" which is a problem for me because I'm trying to fit it into a precisely laid out subplot. Setting PlotBoxAspectRatio doesn't work either (two axes show up) so what can I do to fix this? Thanks!

xize dong

very useful !

Vojtech

Does not work with transparent background, i.e. set(gcf,'color','none');
Legend is grayed out in R2018b. It can be workedaround by plotting new empty entries after breaking axis: plot(nan,nan,'line specifications');

Thank you Petre, and thanks @USTC for the tip concerning the legend!

Legend is grayed out which makes this useless for 2 graph plots in same figure.

Greg Holst

Thank you, Petre.

Vojtech

USTC

Legend missing could be solved by modifying "breakaxis" function
row 257
change into
uistack([leftAxes rightAxes breakAxes annotationAxes],'down',zOrder)

USTC

Legend missing could be solved by modifying "breakaxis" function
row 257
change into
uistack([leftAxes rightAxes breakAxes annotationAxes],'down',zOrder)

How would I change this to split the y-axis instead?

Jusrt want to update my previous comment, the change of break lines to a single line only happened because of setting Y limits to ylim([0,inf]). When a fixed upper limit is set, for example ylim([0,1]), this bug doesn't appear.

Author does not update the code, and it starts to work worse and worse in newer versions of Matlab. Starting from ~2015 version you have to manually add legend to breakInfo.leftAxes, because the original legend forever disappears behind the axes (cannot bring it back). In the current 2017 version the break itself doesn't show up as "nice broken lines with a gap" anymore, but just a single line that doesn't immediately strike a viewer as a break in the axis. Unfortunately, I cannot recommend to use this code in the current version of MATLAB.

Great piece of code but in the current version of Matlab, the legend doesn't render at all.

Cloud Yang

mh

Karl

This doesn't seem to work with the MATLAB function "datetick". Specifically, the dates on the right side of the are wrong while the dates on the left side are correct. This is possibly related to Wenzhen's comment about XTickLabels.

Real life saver. Extremely easy to use, and produce exactly what I wanted - a break in the axis. Thanks for this!

Amazing work! It's exactly what I am looking for. Thanks for making it available!

Liam Daly

Rene Werner

@ multiple breaks (as I had the the same question): Just run the code iteratively, i.e. replace the line

h = breakxaxis([2 3]);

in the "SimpleExample.m" by

h = breakxaxis([2 3]);
hh = breakxaxis(h.rightAxes , [3.7 4.2])
hhh = breakxaxis(hh.rightAxes , [4.5 4.8])

why does the legend disappears?

SH

This worked great until 2014b came out.... Does anyone know how to fix this??? Peter, PLEASE!!! Thanks in advance >_>^

imtiyaz

Thanks for sharing. But I don't want to this whole break visible I just want --//-- in my x-axis. Can you suggest how is it possible through your function.

physicsnh

physicsnh

Thank you!

Ming Wu

The legend seems to disappear behind the plot (becoming invisible) using the Matlab 2015a version. I've tried a few things to fix this but nothing seems to work. Does anyone have any ideas to fix this?

tealover

This is a great, good looking, fool proof and easy to use function. Good job!

Wenzhen

Thanks! It's a nice and convenient function. However, there is a little bug about making the XTickLabel. In the main function, you've rearranged the XTick array, but not the XTickLabel array. As far as adding a similar line to the XTick array part, the problem would be fixed.

Mar

Thanks it's very useful, great!!
I have one question. When i make two breaks in the same plot the axes left and right don't keep the x scale. Do you know if is it possible to keep it?
Thank you very much.

Would be nice if it could support multiple breaks. I, in particular, need that.

Mark

Pretty awesome extension, easy to use.

Updates

1.2.0.0

Added a screen shot

1.1.0.0

Fixed a bug that caused plots to be misaligned in some complex figures.

MATLAB Release Compatibility
Created with R2013a
Compatible with any release
Platform Compatibility
Windows macOS Linux
Acknowledgements

Inspired by: BreakAxis, BreakXAxis, BreakPlot

Inspired: Aesethetic Axis Breaks, Break Y Axis