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

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!

 Accepted Answer

xlim=get(gca,'xlim');
hold on
plot(xlim,[30 30])

2 Comments

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.
bar(X);
hold on
plot(xlim,[30 30], 'r')
works too! Thank you all!

Sign in to comment.

More Answers (1)

A bit shorter:
hline(30,':k','This Line is horizontal')

Categories

Community Treasure Hunt

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

Start Hunting!