필터 지우기
필터 지우기

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

조회 수: 96 (최근 30일)
Thor
Thor 2013년 2월 1일
편집: Pablo Sánchez 2020년 12월 8일
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')
  댓글 수: 1
Pablo Sánchez
Pablo Sánchez 2020년 12월 8일
편집: Pablo Sánchez 2020년 12월 8일
Does hline() exist? Is yline()

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

카테고리

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