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?
0 件のコメント
採用された回答
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';
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'
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/176377/image.png)
4 件のコメント
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.
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!