How to edit scatter plot legend?

조회 수: 16 (최근 30일)
Sara Bashah
Sara Bashah 2019년 5월 21일
댓글: Walter Roberson 2019년 5월 21일
Hi,
I have a problem changing the color of markers for my legend.
I made the scatter plots separately with different size and color of the markers (see attachment), towards the end I use the following:
for k1 = 1:length(A)
scatter(A(k1),B(k1), 50, 'r', 'filled')
end
hold on
legend ('Living single corals','Living coral thicket', 'Basaltic boulders','Basaltic cobbles','Coarse sands', 'Ripples', 'Coral debris', 'Hardground slab')
xlabel('Distance, m');
ylabel('Depth, m')
set (gca,'FontSize',14)
hold on
I would like the legend to be the same as in the plot, however, the legend came up to be just one size and one color.
Appreciate your help.
Thank you,
Sara

답변 (1개)

Walter Roberson
Walter Roberson 2019년 5월 21일
Every scatter call generates a graphics object and by default legend draws labels by order of graphics object.
  댓글 수: 2
Walter Roberson
Walter Roberson 2019년 5월 21일
That scatter in a loop can be replaced with a single scatter call
scatter(A, B, 'k', 'filled')
Sara Bashah
Sara Bashah 2019년 5월 21일
Thank you. Problem solved!
I removed the loop and added each legend to the next scatter plot script, e.g:
scatter(A,B, 80, 'k', 'filled')
legend('Living single coral')
scatter(A,B, 80, 'k', 'filled')
legend('Living single coral','Living coral thicket')
scatter(A,B, 50, 'b', 'filled')
legend('Living single coral','Living coral thicket','Basaltic boulders')
scatter(A,B, 50, 'c', 'filled')
legend('Living single coral','Living coral thicket','Basaltic boulders', 'Basaltic cobbles')

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Legend에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by