Is it possible to have a line graph with a different marker for each point on the same line?
22 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Akzeptierte Antwort
Matt J
am 31 Jan. 2024
Bearbeitet: Matt J
am 31 Jan. 2024
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 Kommentar
Walter Roberson
am 31 Jan. 2024
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.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Discrete Data Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!