Varying the area of points according to each individual x value
2 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (2 件)
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
0 件のコメント
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');
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/172961/image.png)
1 件のコメント
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 Center および File Exchange で Scatter Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!