How to plot vertical lines for reference using vline?

조회 수: 90 (최근 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
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 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