Why is the marker size in the legend of a SCATTER plot not equal to the marker size in the plot?
조회 수: 32 (최근 30일)
이전 댓글 표시
MathWorks Support Team
2009년 12월 2일
편집: MathWorks Support Team
2015년 1월 30일
If I execute the following code:
figure; hold on
s1 = scatter(1, 1, 150, 'k', 'o')
s2 = scatter(1, 2, 150, 'k', '+')
s3 = scatter(2, 1, 150, 'k', 'x')
h = legend('Circle', 'Plus', 'X', 'Location', 'NorthEast');
set(h, 'FontSize', 14)
axis([0 3 0 3])
the marker size in the legend is different from that in the scatter plot. How can I set these marker sizes to be equal when using the SCATTER function?
채택된 답변
MathWorks Support Team
2013년 10월 18일
The ability to automatically equalize the marker size of the legend and plot markers when using the SCATTER function is not available in MATLAB 7.9 (R2009b).
You may use either of the following workarounds to create a scatter plot in which the legend markers have the same size as the plot markers:
1. Manually set the marker size of the patch objects in the legend. Note that the marker area input to the SCATTER function is specified in square points, whereas the 'MarkerSize' property of a patch object is given in points:
M = findobj(h,'type','patch') % Find objects of type 'patch'
set(M,'MarkerSize', sqrt(150)) %Calculate marker size based on size of scatter points
Note that this workaround only applies to releases R2014a and prior. The legend graphics object hierarchy changed in R2014b.
2. Use the PLOT function instead of the SCATTER function:
figure; hold on
plot(1,1,'ko', 'MarkerSize', 12)
plot(1,2,'k+', 'MarkerSize', 12)
plot(2,1,'kx', 'MarkerSize', 12)
h = legend('Circle', 'Plus', 'X', 'Location', 'NorthEast');
set(h, 'FontSize', 14)
axis([0 3 0 3])
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Scatter Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!