Home » MATLAB
Category Archives: MATLAB
I have recently attempted to use MATLAB to plot grouped bar plots (similar to the BAR(Y,’grouped’) call) together with their error bars. It’s not straightforward. There are a few user-made custom function on the File Exchange that tackle this issue, but I wasn’t all that happy with the graphic results. So I’ve made my own wrapper function that successively calls BAR, then ERRORBAR, taking care to overlay the error bars right on top of the corresponding bars. I think that the function could be useful to others, so I’ve uploaded it to the File Exchange: ERRORBAR_GROUPS produces customizable grouped bar plots with overlaid error bars.
At its most basic, this function produces bar plots similar to those obtained using MATLAB’s BAR(Y,’grouped’) function call, and then overlays error bars onto the corresponding bars.
ERRORBAR_GROUPS allows customizing the plot in several ways. For instance, both the width of the bars themselves and that of the error bars can be adjusted. The function allows asymmetric values for the lower and upper bounds of the error bars. The colors of the bars and error bars can also be customized. By default, ERRORBAR_GROUPS uses the function DISTINGUISHABLE_COLORS by Timothy E. Holy (which is a great feature, by the way!).
ERRORBAR_GROUPS allows transmitting optional input property-value pairs to both the BAR and ERRORBAR functions, making it quite versatile.
Here are some examples of what ERRORBAR_GROUPS can do.
Basic usage. Plot 3 groups with 8 bars each and their corresponding error bars.
The upper and lower bounds of the error bars need not be the same. Here is an example with the lower bounds set to be 0, effectively plotting only the upper bounds.
When plotting smaller numbers of groups and bars, it might be visually more appealing to reduce the width of the bars and of the error bars.
The function can pass PropertyName – PropertyValue pairs of input arguments to both the BAR and ERRORBAR functions, which allows for considerable customization!