Add cut line (horizontal line) in bar graph

조회 수: 76 (최근 30일)
Dionisio Mendoza
Dionisio Mendoza 2020년 6월 30일
댓글: Image Analyst 2022년 9월 20일
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]);

채택된 답변

Image Analyst
Image Analyst 2020년 6월 30일
편집: Image Analyst 2020년 6월 30일
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
Lavanya
Lavanya 2022년 9월 20일
Ok, I will try to explain in a better way. As shown in 'image1.jpg', by using the ginput() , able to select the coordinates and using xline it's appearing as blue line. My question is If I want to try the ginput values manually( By using Editfield) the coordinates from the graph. Is it possible to that?
For example:
If I will give x=0.001,y = 12, from the edit field, 'image1.jpg', 1st blue line should appear.
Image Analyst
Image Analyst 2022년 9월 20일
Yes, does it not do that? Where did it draw the line when you ran my code. Perhaps start your own discussion thread.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Duijnhouwer
Duijnhouwer 2020년 6월 30일
편집: Duijnhouwer 2020년 6월 30일
hold on
plot(xlim,[5 5],'r-','LineWidth',2)

카테고리

Help CenterFile Exchange에서 Labels and Annotations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by