Create line between plot points

조회 수: 337 (최근 30일)
Kenneth Bisgaard Cristensen
Kenneth Bisgaard Cristensen 2021년 7월 28일
답변: Steven Lord 2021년 7월 28일
Hi Community,
Is there anyway to connet the * in this plot with a line?

채택된 답변

Star Strider
Star Strider 2021년 7월 28일
Yes.
x = [0 10 20 30];
y = [355 433 510 590];
figure
plot(x, y, '*-r')
grid
Ax = gca;
Ax.XMinorGrid = 'on';
Ax.YMinorGrid = 'on';
Connected!
.

추가 답변 (2개)

KSSV
KSSV 2021년 7월 28일
You would have plotted them using
plot(x,y,'*r')
So use:
plot(x,y,'*r')
hold on
plot(x,y,'b')
You can speecify your required markers. Read about plot.
  댓글 수: 2
Kenneth Bisgaard Cristensen
Kenneth Bisgaard Cristensen 2021년 7월 28일
Hi KSSV,
Thanks, I have tried that, but it does not work for the plot.
KSSV
KSSV 2021년 7월 28일
Why not? Can you show us the code which you have tried?

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


Steven Lord
Steven Lord 2021년 7월 28일
It depends on how you plotted the points.
Case 1: you plotted all the data at once with just the markers
x = 1:10;
y = x.^2;
h = plot(x, y, '*');
Solution: either update the LineStyle property of the object or add a line style to your plot call.
x = 1:10;
y = x.^2;
h = plot(x, y, '-*'); % This line changed
title('With line style added to the plot call')
x = 1:10;
y = x.^2;
h = plot(x, y, '*');
h.LineStyle = ':'; % This line added
title('With line style set (to a different style than above) after the fact')
Case 2: you plotted each point in turn in their own line.
x = 1:10;
axis([0 10 0 100])
hold on
for whichPoint = 1:numel(x)
plot(x(whichPoint), x(whichPoint).^2, '*');
end
The solutions I'd recommend in this case would be either to assemble the vector inside the loop and plot it after the loop is complete (which reduces to case 1 above) or to use an animatedline.
x = 1:10;
axis([0 10 0 100])
hold on
h = animatedline('Marker', '*', 'LineStyle', '-'); % This line added
for whichPoint = 1:numel(x)
addpoints(h, x(whichPoint), x(whichPoint).^2); % This line changed
end
title('animatedline approach')
If you're using some other approach to plot these points, please show us a small sample of code you're using to plot the points.

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by