How to draw lines in matlab figure

482 ビュー (過去 30 日間)
Safi ullah
Safi ullah 2017 年 4 月 15 日
回答済み: Steven Lord 2019 年 11 月 11 日
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

採用された回答

Star Strider
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 件のコメント
Omkar Paranjape
Omkar Paranjape 2019 年 11 月 11 日
How to draw horizontal lines?
Star Strider
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
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.

カテゴリ

Help Center および File ExchangeInteractive Control and Callbacks についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by