This is an example of how to create a stacked bar chart in MATLAB®.
Read about the "bar" function in the MATLAB documentation.
For more examples, go to MATLAB Plot Gallery - http://www.mathworks.com/discovery/gallery.html
MathWorks Plot Gallery Team (2021). MATLAB Plot Gallery - Stacked Bar Chart (https://www.mathworks.com/matlabcentral/fileexchange/35272-matlab-plot-gallery-stacked-bar-chart), MATLAB Central File Exchange. Retrieved .
Inspired: superbar
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Create scripts with code, output, and formatted text in a single executable document.
1. The order of of the colours on the bars and on the legend is opposed. This doesn't look nice.
2. Irrespective to this example: 'stack' doesn't work for a stacked single bar. Fake data for the second bar should be added to the input data.