Clear Filters
Clear Filters

How to overlay single data points on bar graph in MATLAB?

39 views (last 30 days)
I am trying to plot a bar graph with means of 9 data points. I want to plot the bar graph with individual data points overlaid on the bar. Here is the code to generate the bar graph. I want to overlay each bar with the individual data points whose average is y. Any suggestions for how to do this would be helpful. Thank you!
x_num = [1:4];
x = categorical({'High PU-High RU','High PU-Low RU', 'Low PU-High RU', 'Low PU-Low RU'});
y = [0.557954545, 0.671394799, 0.543181818, 0.660227273];
figure
bar(x,y,0.4)
title('Economic Performance')
xlabel('Conditions')

Accepted Answer

Cris LaPierre
Cris LaPierre on 17 Mar 2021
Here's an example overlaying a datapoint contianing the mean value.
x = categorical({'High PU-High RU','High PU-Low RU', 'Low PU-High RU', 'Low PU-Low RU'});
y = [0.557954545, 0.671394799, 0.543181818, 0.660227273];
bar(x,y,0.4)
title('Economic Performance')
xlabel('Conditions')
hold on
plot(x,y,'o')
hold off
The challenge will perhaps be that all the data for each bar will share the same X value, so all the points will fall in a single line.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!