How to plot vertical lines for reference using vline?
조회 수: 90 (최근 30일)
이전 댓글 표시
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
2018년 4월 23일
Having a quick look at your example - is this what you're trying to achieve?
답변 (1개)
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:
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!