Is it possible to have a line graph with a different marker for each point on the same line?
21 次查看(过去 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;
0 个评论
采纳的回答
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
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 Center 和 File Exchange 中查找有关 Discrete Data Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!