How to associate the 'MarkerSize' to a value that means the radius of a plotted circle?

956 views Asked by At

I have three vectors of the same length. Two of them contain the X and Y coordinates of what I want to plot. The third one contains values that I want to associate the radius of the plotted circle.

I have read that 'MarkerSize' in plot corresponds the number of points in the circumference, and if I want to use scatter, the third vector corresponds to the area of the plotted circle.

Nonetheless, I want my third vector to be associated with the radius

As such, how to associate the size of the circles with the radius?

I have this using plot:

hold on;
for nd = 1 : 24
    plot(xL(nd), -yL(nd), 'o', 'MarkerFaceColor', 'g', 'MarkerEdgeColor', 'k', 'MarkerSize', attribute(nd))
end

And this using scatter:

hold on;
for nd = 1 : 24    
    scatter(xL(nd), -yL(nd), attribute(nd), 'o', 'MarkerFaceColor', 'k', 'MarkerEdgeColor', 'k')
end

Thanks in advance for this help.

1

There are 1 answers

2
rayryeng On BEST ANSWER

Assuming you want to use MarkerSize as the attribute for plot, as you said, this number reports the circumference of the plotted marker in pixels.

Well, you know there's a relationship between the circumference of a circle and its radius:

Source: Math Is Fun

Therefore, the circumference of a circle is equal to pi multiplied by the diameter, which is twice the radius... so:

C = 2*pi*r

C would be the MarkerSize attribute. So, given a radius, simply multiply by 2*pi to get the desired circumference. Bear in mind that the above computation will yield floating point values, so either take the floor, take the ceil or round to get the desired effect.

In other words, do this to your attribute vector, assuming you are reporting the radius:

attribute = floor(2*pi*attribute);

Now use this with MarkerSize and plot.


On the other hand, if you want to use scatter... well you know there's a relationship between the area of a circle and its radius:


(source: whstatic.com)

Source: WikiHow

Therefore, given the radius, simply square the radius and multiply by pi to get the area, then use this as the third parameter to scatter... again, accounting for floating-point precision:

attribute = floor(pi*attribute.^2);

You can now use this with scatter.