How to plot vertical lines for reference using vline?

92 ビュー (過去 30 日間)
Jonas Lara
Jonas Lara 2018 年 4 月 23 日
編集済み: Pawel Jastrzebski 2018 年 4 月 24 日
Im using vline and hline unsuccesfully. It seems that doesn't work when i need it. Example:
if true
x = -10:.2:10;
y = sin(x)+2;
plot(x, y)
vline(0, 'k')
hline(0, 'k')
grid minor
axis([-5 5 -5 5])
hold on
y = sin(x) - 2;
plot(x,y)
end
  4 件のコメント
Pawel Jastrzebski
Pawel Jastrzebski 2018 年 4 月 23 日
Jonas Lara
Jonas Lara 2018 年 4 月 23 日
編集済み: Jonas Lara 2018 年 4 月 23 日
wow, thank you. It is more than i need, i guess it will work perfectly. Let me try it and come back with a feedback.

サインインしてコメントする。

回答 (1 件)

Pawel Jastrzebski
Pawel Jastrzebski 2018 年 4 月 24 日
編集済み: Pawel Jastrzebski 2018 年 4 月 24 日
I've moved my comment to the answer so the question can be closed. I've also tried to copy your example to show you what I think you're trying to achieve:
% DATA
x = -10:.2:10;
y0 = sin(x);
y1 = y0+2;
y2 = y0-2;
% PLOTTING
f(1) = figure; % create a new figure window
ax(1)= gca(); % handle to the current's figure axis
% Handles to the plot lines.
% Alternatively you could write it as:
% p(1:3) = plot(x, [y0; y1; y2]);
p(1) = plot(x,y0);
hold on
p(2) = plot(x,y1);
p(3) = plot(x,y2);
% USE THE HANDLES TO CHANGE THE PROPERTIES OF THE AXES AND LINES
set(p(1),...
'LineWidth', 0.5,...
'LineStyle', '--');
set([p(2) p(3)],...
'LineWidth', 2,...
'LineStyle', '-');
set(ax(1),...
'XAxisLocation','origin',...
'YAxisLocation','origin',...
'XLim', [-8 6],...
'YLim', [-4 2],...
'XMinorGrid','on',...
'YMinorGrid','on');
set(ax(1).Title,...
'String','Sine plots',...
'Color',[1 0 0],...
'FontSize',14);
set(ax(1).XLabel,...
'String', 'X-label');
set(ax(1).YLabel,...
'String', 'Y-label');
set([ax(1).XLabel ax(1).YLabel],...
'Color',[0 0 1],...
'FontSize',12);
Output:
All of the properties that you can change are listed in the following:

カテゴリ

Help Center および File ExchangeGrid 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