Showing markers to plot legend

Hiya! I got this code (below) and I want to add the markers to a legend, how would I go about this?
figure(4); clf
p = plot(faun.age, faun.depth, '-diamond', 'LineWidth', 1.2);
grid on
set(gca, 'YDir', 'reverse')
xlabel('Age (ka BP)')
ylabel('Depth (mm)')
title('Age-Depth Relationship with Nps data')
p.MarkerEdgeColor = [1 0.5 0];

Risposte (2)

Star Strider
Star Strider il 10 Nov 2026 alle 22:15

1 voto

You have to call the legend function in order to produce a legend for your figure.
Add that and it should work.
There are two closely related ways to handle this.
faun.age = [5 7 4 9];
faun.depth = [2 3 4 3];
figure(1)
p = plot(faun.age, faun.depth, '-diamond', 'LineWidth', 1.2, 'displayname', 'depth');
grid on
set(gca, 'YDir', 'reverse')
xlabel('Age (ka BP)')
ylabel('Depth (mm)')
title('Age-Depth Relationship with Nps data')
p.MarkerEdgeColor = [1 0.5 0];
legend show
figure(2)
p = plot(faun.age, faun.depth, '-diamond', 'LineWidth', 1.2);
grid on
set(gca, 'YDir', 'reverse')
xlabel('Age (ka BP)')
ylabel('Depth (mm)')
title('Age-Depth Relationship with Nps data')
p.MarkerEdgeColor = [1 0.5 0];
legend('depth')

Prodotti

Release

R2025b

Richiesto:

il 10 Nov 2026 alle 22:06

Risposto:

il 11 Nov 2026 alle 5:42

Community Treasure Hunt

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

Start Hunting!

Translated by