Plot of data representing particles of various size and various properties (e.g. temperature)

4 次查看(过去 30 天)
hi there
I have a model that handles particles and lets them react. in the end, I have the coordinates in [x,y] where the particles center lies, it's radius and for instance its temperature.
I would now like to plot that particle at [x,y], as a dot representing its size (e.g. with MarkerSize?) and color by temperature.
Is there anything around that can actually do this? The problem is also that the particle size should be realistically displayed.
thank you for your help! maurice

回答(3 个)

Patrick Kalita
Patrick Kalita 2011-4-18
You should be able to do this with the scatter command. The first two inputs are the x and y locations. The third input is the size of the marker to be drawn. And the fourth controls the color. The only tricky bit would be to scale the temperature data to a range of appropriate marker sizes.
Here's a very simply example that just scales the T data so that the third input argument is in the range [0 100]:
x = rand(1, 10);
y = rand(1, 10);
T = x + y;
scatter(x,y,T./max(T) * 100, T,'filled')

Teja Muppirala
Teja Muppirala 2011-4-18
I think the downside with using SCATTER is that the marker doesn't change size with zooming. Using PATCH might be another option:
N = 100; %Number of points
r = 0.2*rand(N,1); %Radii
T = rand(N,1); %Temperatures
p = randn(N,2); %Positions
colordef(figure,'black');
q = linspace(0,2*pi,32)';
C = [cos(q) sin(q)];
hold all;
for n = 1:numel(r)
patch(r(n)*C(:,1)+p(n,1), r(n)*C(:,2)+p(n,2),T(n),'edgecolor','none');
end
axis equal;
set(gca,'Clim',[0 1]);
alpha 0.9
colorbar

Artur Palha
Artur Palha 2013-1-29
编辑:Artur Palha 2013-1-29
A small change to the option Teja Muppirala gave can give a considerable speed up, especially when plotting many data points. The alternative is to plot all the patches at once in the following way:
N = 1000; %Number of points
r = 0.2*rand(N,1); %Radii
T = rand(N,1); %Temperatures
p = randn(N,2); %Positions
figure(1)
clf(1)
colordef(1,'black');
q = linspace(0,2*pi,32)';
C = [cos(q) sin(q)];
hold all;
% Teja Muppirala approach
tic
for n = 1:numel(r)
patch(r(n)*C(:,1)+p(n,1), r(n)*C(:,2)+p(n,2),T(n),'edgecolor','none');
end
toc
axis equal;
set(gca,'Clim',[0 1]);
alpha 0.9
colorbar
hold off
figure(2)
clf(2)
colordef(2,'black');
hold all;
% faster approach
tic
patch(bsxfun(@plus,bsxfun(@times,r',repmat(C(:,1),[1 N])),p(:,1)'), bsxfun(@plus,bsxfun(@times,r',repmat(C(:,2),[1 N])),p(:,2)'),T','edgecolor','none');
toc
axis equal;
set(gca,'Clim',[0 1]);
alpha 0.9
colorbar
hold off
I made this change because I need to plot thousands of data points. for 1e5 data points I get a speedup of about 30x.

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by