Scatter Plot marker size scale
조회 수: 30 (최근 30일)
이전 댓글 표시
I am making a scatter plot with 4 variables- x, y, marker size, and marker color. I made the colormap easy enough, but how do I add a scale to give reference to what marker sizes correspond to the numerical values of each data point. Something like the one shown below.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1311725/image.png)
댓글 수: 0
답변 (1개)
Amith
2023년 3월 2일
As per my understanding you wanted the markers in different sizes and want those to be labeled in the legend with the size being shown .You can achieve this by refering to the below code -
x = 1:3;
y1 = x.^2;
y2 = x.^3;
% Define marker sizes for each point
ms1 = [4, 6, 8];
sizes = [50,300,650];
% Plot the data with different marker sizes
figure;
for size = 1:3
hold on;
plot(x(size), y1(size), 'o', 'MarkerSize', ms1(size));
hold off;
end
%write the legend corresponding values
x = cellstr(num2str(sizes', '%-d'));
% Add a legend with marker sizes
legend(x);
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Legend에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!