How to plot vertical lines for each data point?

조회 수: 32 (최근 30일)
Victoria Wilson
Victoria Wilson 2020년 3월 11일
편집: Victoria Wilson 2020년 3월 11일
I have a line graph plot which is giving me a correct figure looking like the following:
However, my task is to recreate a zonation simulating the following figure:
I therefore need to add vertical lines to the plot at each data point along the x axis.
Any help would be greatly appreciated.

채택된 답변

Steven Lord
Steven Lord 2020년 3월 11일
Combine a plot plot (or a line plot) and a stem plot.
x = 0:10;
y = x.^2;
plot(x, y);
hold on;
stem(x, y, 'Marker', 'none');

추가 답변 (1개)

Ameer Hamza
Ameer Hamza 2020년 3월 11일
편집: Ameer Hamza 2020년 3월 11일
Check this example
% Example data
x = logspace(0,1,30);
y = log(x);
% plot original line
plot(x,y);
hold on;
% plot vertical lines
line_coordinates = [x' x' zeros(size(x')) y'];
line_coordinates = mat2cell(line_coordinates, ones(numel(x),1), [2 2])';
line_coordinates(3,:) = {'k'};
plot(line_coordinates{:})
  댓글 수: 3
Ameer Hamza
Ameer Hamza 2020년 3월 11일
Check Steven's answer. It mentions a cleaner solution.
Victoria Wilson
Victoria Wilson 2020년 3월 11일
Thank you for your help Ameer!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by