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!

 채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2013년 2월 1일
편집: Azzi Abdelmalek 2013년 2월 1일

2 개 추천

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일

1 개 추천

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

카테고리

도움말 센터File Exchange에서 Line Plots에 대해 자세히 알아보기

질문:

2013년 2월 1일

편집:

2020년 12월 8일

Community Treasure Hunt

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

Start Hunting!

Translated by