Effacer les filtres
Effacer les filtres

Varying the area of points according to each individual x value

3 vues (au cours des 30 derniers jours)
Student
Student le 20 Jan 2015
Modifié(e) : Chris le 20 Jan 2015
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 commentaire
Ced
Ced le 20 Jan 2015
What "area" are you talking about? The size of the plot? size of your marker?

Connectez-vous pour commenter.

Réponses (2)

Chris Barnhart
Chris Barnhart le 20 Jan 2015
Modifié(e) : Chris le 20 Jan 2015
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 le 20 Jan 2015
Modifié(e) : Image Analyst le 20 Jan 2015
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 commentaire
Ced
Ced le 20 Jan 2015
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

Connectez-vous pour commenter.

Catégories

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

Community Treasure Hunt

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

Start Hunting!

Translated by