Showing markers to plot legend
Show older comments
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];
Answers (2)
Star Strider
on 10 Nov 2026 at 22:15
1 vote
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')
Categories
Find more on Lighting, Transparency, and Shading in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
