필터 지우기
필터 지우기

Varying the area of points according to each individual x value

조회 수: 3 (최근 30일)
Student
Student 2015년 1월 20일
편집: Chris 2015년 1월 20일
I am plotting a scatter plot that plots y versus x for many individual values but I want the area to vary according to an additional parameter t, which is different for each value of x.
So I want to be able to say that if t is between, say, 1 and 2 then the area should be A1. If t is between 2 and 3 then the area should be A2 etc. But obviously, the area of each x value will therefore need to be separately identified with a separate area? Is there a relatively easy way that I could incorporate this into the code that I already have which plots the graph exactly how I want it?
Thank you!
  댓글 수: 1
Ced
Ced 2015년 1월 20일
What "area" are you talking about? The size of the plot? size of your marker?

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

답변 (2개)

Chris Barnhart
Chris Barnhart 2015년 1월 20일
편집: Chris 2015년 1월 20일
Not sure if any way to do without a loop, but at least the loop can be on the number of marker sizes, not data points. Here is an example using interp1 to turn t into a value used for marker size. The commented plot statement also changes the marker type.
% test data
x = rand(100,1);
y = rand(100,1);
t = 0.1 + 999*rand(100,1);
map_y=[0, 250, 500, 750, 1000]; % value that t should fall between
map_x=[1,2,3,4,5]; % value returned after t mapped though y
t_map = interp1(map_y, map_x, t); %t_map could be used as a 'marker' size or selecting a different marker.
t_map = round(t_map);
markers = '.+os*';
clf
for area_loop = map_x
ndx = find(t_map == area_loop); % select the data points for this specific area
plot(x(ndx), y(ndx), '.', 'MarkerSize', 10*area_loop );
% plot(x(ndx), y(ndx), markers(area_loop),'MarkerSize', 2*area_loop );
hold on
end
hold off

Image Analyst
Image Analyst 2015년 1월 20일
편집: Image Analyst 2015년 1월 20일
You can pass in the sizes as the third argument to scatter:
% Create sample data
x = 2 * rand(1, 100);
y = 2 * rand(size(x));
% Initialize
A1 = 5;
A2 = 30;
markerSizes = A1 * ones(size(x));
% Let's say parameter t is true if x and y are both more than 1.
t = x>1 & y>1;
% Make those markers where t is true to be size A2
markerSizes(t) = A2;
% Create the scatter plot.
scatter(x, y, markerSizes, 'filled');
  댓글 수: 1
Ced
Ced 2015년 1월 20일
Just a detail: It should be
% Let's say parameter t is true if x and y are both more than 5.
t = x>5 & y>5

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

카테고리

Help CenterFile Exchange에서 Scatter Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by