Add cut line (horizontal line) in bar graph

118 views (last 30 days)
Hello everybody.
I just made a bar graph using the bar function, but I want a horizontal line to appear on the x axis. I know the xline function exists, but my MATLAB version appears to be old. Below I show the simple code.
x = [3.10,8.17,9.84,4.71,1.43,6.90,3.70,10.24,9.61,5.92,4.51,7.12,2.99,4.73,5.96,9.58,7.22,4.91,4.80,8.79,8.45,6.38,2.83,1.10,7.47,5.36,10.42,5.11,5.15,4.25,7.65,7.05,3.60,4.08,7.29,4.72,4.90,8.74,5.42,9.96,4.88,4.06,4.68,6.67,4.16,6.20,7.34,2.96,7.16,6.34,9.20,4.66,7.42,3.32,8.45,5.59,4.97,5.50,6.20,1.30,3.84,3.97,7.98,6.71,5.26,6.39,6.24,9.19,9.27,4.63,7.20,7.45,4.94,7.57,6.79,8.58,6.51,5.98,5.44,5.47,6.67,5.33,7.59,5.82,4.24,2.86,3.14,4.93,4.15,4.58,7.20,5.33,4.17,6.30];
bar(x,0.8,'w');
ylabel('volume')
xlabel('Pacients')
xticks([1:94]);
yticks([1:11]);

Accepted Answer

Image Analyst
Image Analyst on 30 Jun 2020
Edited: Image Analyst on 30 Jun 2020
Horizontal line on the x axis. What does that mean? The x axis is already horizontal so the line would overlap it. Do you mean horizontal line parallel with the x axis, intersecting the y axis at some value? xline() gives a vertical line, not a horizontal line. So we're not sure what you want. So I'm doing it both ways:
x = [3.10,8.17,9.84,4.71,1.43,6.90,3.70,10.24,9.61,5.92,4.51,7.12,2.99,4.73,5.96,9.58,7.22,4.91,4.80,8.79,8.45,6.38,2.83,1.10,7.47,5.36,10.42,5.11,5.15,4.25,7.65,7.05,3.60,4.08,7.29,4.72,4.90,8.74,5.42,9.96,4.88,4.06,4.68,6.67,4.16,6.20,7.34,2.96,7.16,6.34,9.20,4.66,7.42,3.32,8.45,5.59,4.97,5.50,6.20,1.30,3.84,3.97,7.98,6.71,5.26,6.39,6.24,9.19,9.27,4.63,7.20,7.45,4.94,7.57,6.79,8.58,6.51,5.98,5.44,5.47,6.67,5.33,7.59,5.82,4.24,2.86,3.14,4.93,4.15,4.58,7.20,5.33,4.17,6.30];
bar(x,0.8,'w');
ylabel('volume')
xlabel('Pacients')
xticks([1 : 10 : 94]);
yticks([1 : 11]);
grid on;
% Draw a vertical line at x = 50;
line([50, 50], ylim, 'Color', 'm', 'LineWidth', 2);
% Draw a horizontal line at y = 6;
line(xlim, [6, 6], 'Color', 'r', 'LineWidth', 2);
  5 Comments
Image Analyst
Image Analyst on 20 Sep 2022
Yes, does it not do that? Where did it draw the line when you ran my code. Perhaps start your own discussion thread.

Sign in to comment.

More Answers (1)

Duijnhouwer
Duijnhouwer on 30 Jun 2020
Edited: Duijnhouwer on 30 Jun 2020
hold on
plot(xlim,[5 5],'r-','LineWidth',2)

Categories

Find more on Labels and Annotations 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!