Vertical grid line for x=0
이전 댓글 표시
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?
채택된 답변
추가 답변 (2개)
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
Image Analyst
2017년 1월 2일
I don't understand. Normally the Y axis is at the left hand side of the axes box. If you want it to remain there, then just don't set YAxisLocation. If you want to move it so that it crosses at the x=0 line, then set YAxisLocation = 'origin'.
The only way to not move the Y axis and have it still be on the left hand side, and to have that left hand side also be the x=0 location is to set xlim to be 0:
% Get current axes limits
xl = xlim();
% Set xl(1) = 0
xl(1) = 0;
% Update the x axes limits.
xlim(xl);
Is that what you want?
Jan w
2017년 1월 2일
Image Analyst
2017년 1월 2일
You're welcome. Maybe you could "Vote" for the answer (under my logo).
the cyclist
2017년 1월 1일
편집: the cyclist
2017년 1월 1일
line([0 0],[0 1],'Color','Black')
댓글 수: 2
Brian Russell
2020년 12월 16일
You simply need to write yline(0) or xline(0) for vertical and horizontal lines.
Star Strider
2020년 12월 17일
Note that xline and yline were introduced in R2018b, 1½ years after this was posted.
카테고리
도움말 센터 및 File Exchange에서 Labels and Annotations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!