How to overlay single data points on bar graph in MATLAB?
39 views (last 30 days)
Show older comments
Prashanti Ganesh
on 17 Mar 2021
Answered: Cris LaPierre
on 17 Mar 2021
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')
0 Comments
Accepted Answer
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.
0 Comments
More Answers (0)
See Also
Categories
Find more on Bar Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!