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

4 Ansichten (letzte 30 Tage)
dormant am 4 Aug. 2023
Kommentiert: Jon am 4 Aug. 2023
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.
##### 0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Akzeptierte Antwort

Jon am 4 Aug. 2023
Bearbeitet: Jon am 4 Aug. 2023
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 KommentareKeine anzeigenKeine ausblenden
dormant am 4 Aug. 2023
That's brilliant, many thanks!
Now I see it in the documentation.
Jon am 4 Aug. 2023
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.

Melden Sie sich an, um zu kommentieren.

### Kategorien

Mehr zu Scatter Plots finden Sie in Help Center und File Exchange

R2023a

### Community Treasure Hunt

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

Start Hunting!

Translated by