필터 지우기
필터 지우기

Vertical grid line for x=0

조회 수: 48 (최근 30일)
Jan w
Jan w 2017년 1월 1일
댓글: Star Strider 2020년 12월 17일
I am using horizontal gridlines for a plot.
ax = gca;
ax.XGrid = 'off';
ax.YGrid = 'on';
How can I add only one vertical line through x=0?

채택된 답변

Star Strider
Star Strider 2017년 1월 1일
You can plot a vertical line anywhere by duplicating the x-coordinate and plotting it against ylim:
figure(1)
plot([0 0], ylim, '-r')
ax = gca;
ax.XGrid = 'off';
ax.YGrid = 'on';

추가 답변 (2개)

Image Analyst
Image Analyst 2017년 1월 1일
The best answer is to use YAxisLocation:
theta = linspace(-pi, pi, 800);
plot(theta, sin(theta), 'b-') % Plot something.
% Make axes go through origin instead of left and bottom sides of axes box.
ax = gca;
ax.XAxisLocation = 'origin'
ax.YAxisLocation = 'origin'
  댓글 수: 4
Jan w
Jan w 2017년 1월 2일
Yes this works fine for me!
Image Analyst
Image Analyst 2017년 1월 2일
You're welcome. Maybe you could "Vote" for the answer (under my logo).

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


the cyclist
the cyclist 2017년 1월 1일
편집: the cyclist 2017년 1월 1일
line([0 0],[0 1],'Color','Black')
See line for details of setting the properties of the line.
  댓글 수: 2
Brian Russell
Brian Russell 2020년 12월 16일
You simply need to write yline(0) or xline(0) for vertical and horizontal lines.
Star Strider
Star Strider 2020년 12월 17일
Note that xline and yline were introduced in R2018b, years after this was posted.

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

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by