Is it possible to have a line graph with a different marker for each point on the same line?
12 ビュー (過去 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!