How can I create a bubble different size plot?
Mostrar comentarios más antiguos
Hi,
I have two vectors with too many data (10000 x 1), I want to create a different size bubble plot, I guess I'd to reduce that data to two new vectors for data plot and one more for bubble size but I'm not sure. Hope you can suggest me.
Thanks

Respuesta aceptada
Más respuestas (4)
Prasad Kalane
el 11 de Dic. de 2015
Editada: Prasad Kalane
el 11 de Dic. de 2015
0 votos
I am not getting your Total idea. but try using following
>> plot(rand(1,10),'bo','MarkerEdgeColor','k','MarkerFaceColor','g','MarkerSize',10)
>> hold on
>> plot(rand(1,8),'ro','MarkerEdgeColor','k','MarkerFaceColor','m','MarkerSize',20)
Joseph Cheng
el 11 de Dic. de 2015
you are best off not using markersize. Markersize is unitless and there is not many explanations on how to set it to correspond to the y or x axis. it can be used if you want to display the items relatively. for instance big vs medium vs small dots. One way around this is to use rectangle. in the example i have below i show markersize not working and in figure 2 use of rectangle.
x = [1 10 100];
y = zeros(size(x));
r = x/2;
figure(1), clf, hold on
for ind = 1:numel(x)
plot(x(ind),y(ind),'bo','markersize',r(ind));
end
figure(2),clf,hold on
for ind = 1:numel(x)
radius = r(ind);
centerX = x(ind);
centerY = y(ind);
rectangle('Position',[centerX - radius, centerY - radius, radius*2, radius*2],...
'Curvature',[1,1],...
'FaceColor','none');
end
axis square
only issue here is that you'll have to make the axis square or equal
x = randi(2000,1,40);
y = randi(4000,1,numel(x))-2000
r = randi(500,1,numel(x))
figure(2),clf,hold on
for ind = 1:numel(x)
radius = r(ind);
centerX = x(ind);
centerY = y(ind);
rectangle('Position',[centerX - radius, centerY - radius, radius*2, radius*2],...
'Curvature',[1,1],...
'FaceColor','none');
end
axis equal
1 comentario
Joseph Cheng
el 11 de Dic. de 2015
Editada: Joseph Cheng
el 11 de Dic. de 2015
use my answer above in conjunction with accumarray(). see http://www.mathworks.com/matlabcentral/answers/129646-collate-data-in-grid for additional information on how to accomplish this.
Luis Lopez
el 11 de Dic. de 2015
0 votos
1 comentario
[Edit. Meant to ask: what do you want done with values over 100%? Is 101.172% meaningful, or do you want bins to limit it to 100%?]
A couple of notes: your data has 10589 points; your x-data i_Engine_Speed has 5431 unique values; your y-data i_Instantaneous_Percent_Load has only 254 unique values. However, using unique(..., 'rows'), you have 9169 unique points.
Since you seem to have much greater resolution in x than y, you'll need to choose your bin sizes carefully...
I wonder if a heat-map might be more appropriate than the circle plot. If you have a more recent version of Matlab and the appropriate toolboxes (I do not), you might consider bar3 or a HeatMap; otherwise, you can search the FEX (I've never used any of these functions).
If you're really set on circles, however, you should be able to do this with the third input to scatter.
Mike Garrity
el 11 de Dic. de 2015
Do you mean something like this?

Here's how I did that:
% Load data
load C:\Users\mgarrity\Downloads\speed_load.mat
% File appears to only have a single dependent var, so make up another
extra_var = randn(size(i_Engine_Speed));
% Histogram the engine speed, and keep the bins
[~,edges,bin] = histcounts(i_Engine_Speed);
nbins = length(edges)-1;
% Turn bin edges into bin centers
x = conv(edges,[.5 .5],'valid');
% Make two arrays to accumulate Y and Size into
y = zeros(1,nbins);
s = zeros(1,nbins);
for i=1:nbins
% Pull out the values for engine speeds in the current bin
mask = bin==i;
tmp_y = i_Instantaneous_Percent_Load(mask);
tmp_s = extra_var(mask);
% Accumulate the values. Use whatever function you like here
y(i) = mean(tmp_y);
s(i) = mean(tmp_s);
end
% Come up with a scale factor for size. Scatter wants points^2.
min_size = 1;
max_size = 200;
range = [min(s) max(s)];
s = min_size + (s - range(1)) * (max_size-min_size) / (range(2)-range(1));
% Plot using scatter
scatter(x,y,s)
grid on
ylabel('Percent load')
2 comentarios
Luis Lopez
el 11 de Dic. de 2015
Mike Garrity
el 14 de Dic. de 2015
The histcounts function was an upgraded "replacement" for an earlier function named histc. You should be able to use that in R2013b to do the same thing. It didn't have as many options, but it should do fine for this job.
Categorías
Más información sobre Color and Styling en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

