# How to add a dashed horizontal line at 0 using plot function?

조회 수: 237 (최근 30일)
Anne Nguyen 2019년 9월 29일
댓글: shahriar sowad 2021년 7월 1일
How I do add a dashed horizontal line on a graph using the plot function?

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

### 채택된 답변

편집: Adam Danz 2019년 10월 2일
Here are 3 options to add a dashed horizontal line to a plot. The 1st option is recommended if you're using matlab r2018b or later.
% Use yline() to plot a horizontal line at y=0 (requires r2018b or later)
% https://www.mathworks.com/help/matlab/ref/yline.html
yline(0,'k--')
% Plot a line at y=0 that spans from x=0 to x=5
plot([0,5],[0,0], 'k--')
% Plot a line at y=0 that spans the current x-limits of your axes
plot([min(xlim()),max(xlim())],[0,0], 'k--')
##### 댓글 수: 3이전 댓글 1개 표시이전 댓글 1개 숨기기
If you zoom into the line you will see that it is plotted at y=0.2.
yes,got it,thanks

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

### 카테고리

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