How to draw lines in matlab figure
조회 수: 78 (최근 30일)
이전 댓글 표시
Hi everyone, I plot simple figure in matlab by using plot(x,y).now I need to draw verticale dashed lines like grid lines at some specific points on x-axis.,what should I do? thanks
댓글 수: 0
채택된 답변
Star Strider
2017년 4월 15일
Try this:
x = 0:20;
y = sin(x*pi/9);
figure(1)
plot(x, y);
hold on
plot([1 1]*4.5, ylim, '--k') % First Vertical Line at ‘x=4.5’
plot([1 1]*13.5, ylim, '--k') % First Vertical Line at ‘x=13.5’
hold off
grid
Also, I like your Emperor penguins!
댓글 수: 2
Star Strider
2019년 11월 11일
plot(xlim, [1 1]*4.5, '--k') % First Horizontal Line at ‘y=4.5’
plot(xlim, [1 1]*13.5, '--k') % First Horizontal Line at ‘y=13.5’
추가 답변 (1개)
Steven Lord
2019년 11월 11일
You could either turn the grid on or use the xline and/or yline functions.
plot(1:10);
grid on
xline(4.5, 'r:')
yline(2*pi, 'c--', 'LineWidth', 2)
With xline and yline, if you pan or zoom the axes the lines still extend to the limits of the axes.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Line Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!