필터 지우기
필터 지우기

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

조회 수: 13 (최근 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
  댓글 수: 1
Maurice
Maurice 2011년 4월 20일
Thank you for your help, this is what I was looking for.
You saved me a lot of work figuring out how to do it.
THANKS

댓글을 달려면 로그인하십시오.


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에서 Surface and Mesh Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by