Vertical grid line for x=0

96 次查看(过去 30 天)
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 中查找有关 Grid Lines, Tick Values, and Labels 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by