Overlay Bar Graphs

This example shows how to overlay two bar graphs.

Define series1 and series2.

x = [1,3,5,7,9]; % place bars at these points along x-axis
series1 = [10,25,90,35,16];
series2 = [7,38,31,50,41];

Create a bar graph of the data in series1. Set the bar width to 0.5. Set the bar color to dark blue by setting the FaceColor property to an RGB color value.

width1 = 0.5;

Use the hold function to retain the first graph. Plot the second bar graph over the first bar graph using a smaller bar width. Specify a different RGB color value for the FaceColor and EdgeColor properties of the second bar graph.

hold on
width2 = width1/2;
hold off

legend('First Series','Second Series') % add legend

The figure contains two bar graphs. MATLAB® plots the dark blue bars behind the light blue bars since the dark blue bars are plotted first. The order of the plotting commands determines the stacking order of the bars.

See Also

| |

Was this topic helpful?