Scatter plot with variable symbol size - it's not linear

조회 수: 4 (최근 30일)
dormant
dormant 2023년 8월 4일
댓글: Jon 2023년 8월 4일
I'm trying to use the feature in the scatter plot where the symbol size is proportional to a variable and it seems that the scaling of the symbol size is not linear.
Here is some test code and the resulting plot:
x = 1:100;
y = ones( size(x) );
scatter( x, y, 100*x, '|' );
xlim( [0 101] );
ylim( [0 2] );
Is this the expected behaviour? I need the symbol size to vary linearly with the variable.

채택된 답변

Jon
Jon 2023년 8월 4일
편집: Jon 2023년 8월 4일
According to the documentation for scatter, the size in "points squared" units, try this
x = 1:100;
y = ones( size(x) );
scatter( x, y, x.^2,'|' );
xlim( [0 101] );
ylim( [0 2] );
  댓글 수: 2
dormant
dormant 2023년 8월 4일
That's brilliant, many thanks!
Now I see it in the documentation.
Jon
Jon 2023년 8월 4일
Your welcome. When first I read the documentation it wasn't really clear to me whether that meant I should take the square root of x, or square it. A little trial and error quickly showed squaring it was the right way to go.

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

추가 답변 (0개)

카테고리

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

태그

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by