Add cut line (horizontal line) in bar graph

57 ビュー (過去 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)
  1 件のコメント
Dionisio Mendoza
Dionisio Mendoza 2020 年 7 月 1 日
Thanks for the help :).

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLabels and Annotations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by