Is it possible to have a line graph with a different marker for each point on the same line?

3 次查看(过去 30 天)
x = 1:5;
y1 = [2, 3, 1, 4, 2];
y2 = [1, 4, 2, 3, 5];
figure;
plot(x, y1, '-o', 'DisplayName', 'Line 1', 'MarkerSize', 8, 'LineWidth', 1.5);
hold on;
plot(x, y2, '-s', 'DisplayName', 'Line 2', 'MarkerSize', 8, 'LineWidth', 1.5);
hold off;
xlabel('X-axis');
ylabel('Y-axis');
title('Line Graph with Different Markers');
legend('Location', 'Best'); % Adjust the legend position
grid on;

采纳的回答

Matt J
Matt J 2024-1-31
编辑:Matt J 2024-1-31
You can effect that as below. I don't see why you'd want it, however.
x = 1:5;
y = [2, 3, 1, 4, 2];
xc=num2cell(x); xc{end+1}=x;
yc=num2cell(y); yc{end+1}=y;
mc={'x','s','v','^','+','-b'}; %Marker and line styles
args=[xc;yc;mc];
H=plot(args{:}); axis padded
h=H(1:end-1);
set(h,'Color','r');
[h.MarkerFaceColor]=deal(h.Color);
  1 个评论
Walter Roberson
Walter Roberson 2024-1-31
The key here is that any one plot line can only have a single marker, so first you draw the continuous line and then you add in markers point by point.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Line Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by