customize size each dot in a scatter plot

22 vues (au cours des 30 derniers jours)
Miguel Usach
Miguel Usach le 30 Jan 2020
Hello!
Lets start... I have an array of data, to simplify, only two columns, X and Y.
I did some previous calculation in teh array, and I only want to plot some positions of the array.
The positions to be plotted are stored in a vector.
To plot the points I just using
plot(Array_specs(index,1),Array_specs(index,2))
so far so good... now, for each x,y I would like to assign different weight by making the dot bigger.
I know this is done with LineWidth.. but linewidth do not accept a vector as an input.. this means that I need to manually plot each point in the scatter plot,
plot(Array_specs(index(i),1),Array_specs(index(i),2), 'LineWidth', number(index(i)) )
the problem is that the function takes really long time, as obviusly it is not optimized. Is any optimum way to do that?
How can assign a different linewidth to each of my XY points without manually check the array?
Best Regards,
Miguel

Réponse acceptée

Image Analyst
Image Analyst le 30 Jan 2020
Try using scatter. With scatter() can specify sizes and colors for each element in your (x,y) pairs.
numPoints = 300;
x = rand(1, numPoints) - 0.5;
y = rand(size(x)) - 0.5;
% Sizes = distance from origin
sizes = 200 * sqrt(x.^2 + y.^ 2);
% Colors according to the jet colormap and distance from origin.
indexes = round(rescale(sizes, 1, numPoints));
colors = jet(numPoints); % Initialize
colors = colors(indexes,:); % Colored according to distance.
% Do the plot
scatter(x, y, sizes, colors, 'filled');
grid on;
0000 Screenshot.png

Plus de réponses (1)

Miguel Usach
Miguel Usach le 31 Jan 2020
Perfect! Thanks!

Catégories

En savoir plus sur Scatter Plots dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by