How to add a horizontal line in a bar plot????

96 次查看(过去 30 天)
Dear all,
i use the command bar for a plot. I want to insert a horizontal line in a bar plot at y = 30. How can I do that? Thank you!

采纳的回答

Azzi Abdelmalek
Azzi Abdelmalek 2013-2-1
编辑:Azzi Abdelmalek 2013-2-1
xlim=get(gca,'xlim');
hold on
plot(xlim,[30 30])
  2 个评论
Image Analyst
Image Analyst 2013-2-1
Isn't the first line unnecessary? xlim is already the x limits - you don't have to call get() to retrieve it, it's already ready to be used "as is". xlim is actually a function itself that returns the x limits.
Thor
Thor 2013-2-2
bar(X);
hold on
plot(xlim,[30 30], 'r')
works too! Thank you all!

请先登录,再进行评论。

更多回答(1 个)

Vivian Hauss
Vivian Hauss 2016-7-19
编辑:Vivian Hauss 2016-7-19
A bit shorter:
hline(30,':k','This Line is horizontal')

类别

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