# Breaking a plot to improve visualization4

Posted by Brett Shoelson,

### Contents

Suppose you wanted to plot data that spanned two distinct ranges of your dependent variable. Showing all the data on a single plot would waste valuable real estate, and changing to a log scale might obscure some of your data. Classically, you might think of using the SUBPLOT function to create two separate axes to visualize the data. Alternatively, you might want to create a single axes, and to break it to reflect the different ranges. Michael Robbins's BREAKPLOT makes short work of that task.

Consider, for example, that you had some sampled engine-speed data collected during two times in the engine's cycle. The first 100 data points are colleced (at sampling times 1:100) while the engine is idling, and the second 100 data are collected (at t = 101:200) while the engine is being revved:

sampleTimes = 1:200;
RPM = [600+rand(1,100)*500, 5500+rand(1,100)*2500];

Note all the wasted "white space" in the traditional plot of these data. Also note how tightly clustered the data can be.

plot(sampleTimes,RPM,'r.')

### BREAKPLOT

Now consider how Michael's function allows you to break the y-axis to reflect the range change:

BreakPlot(sampleTimes,RPM,1500,5000,'Line');

First, this nicely extends the powerful visualization capabilities MATLAB provides out of the box--and the ability to customize functions is often critical.

Second, Michael provided nice options for different break visualizations. The default 'RPatch' produces a ragged patch across the axis. 'Line' (shown above) shows hash marks where the axis is broken. And 'Patch' produces a smoother break reaching across the axis.

Finally, I appreciate Michael's responsiveness when I asked him to address an issue I saw with an earlier version of his code. This demonstrates yet again that the File Exchange is dynamic and ever-improving!

If you have any custom visualizations along these lines, tell us about them in the Comments box below, and share them on the File Exchange!

And by the way, next Friday is the day after Thanksgiving. Bob, Jiro and I will be taking the day off to digest our turkey dinners, and we hope you'll be doing the same. Look for our next Pick of the Week on December 5. Happy Thanksgiving, everyone!

Get the MATLAB code

Published with MATLAB® 7.7

chris replied on : 1 of 4

This Breakplot function is nice. BreakXAxis, also on the file exchange, breaks plots with “//” on the axis that’s broken. Which is more consistent with what I see in publications. I wish matlab would incorporate basic axis-breaking options into their plotting tools. That would make matlab data visualization even more powerful. Some graphing software packages, like Sigmaplot, have this built in and the option is user friendly.

David replied on : 2 of 4

I agree with chris. It would be really nice if Matlab included this in its default graphing package; downloading extra functions can be a pain, especially if you tend to work on multiple computers and it is such a “simple” and pervasive function as this.

Brett replied on : 3 of 4

Thanks, Chris and David. I’ve shared the suggestion with our Developers. Getting this kind of user feedback is very useful to us!

Brian Dzwonkowski replied on : 4 of 4

I am trying to use this code, but it is not plotting my data correctly, nor breaking the data correct.

These postings are the author's and don't necessarily represent the opinions of MathWorks.