フィルターのクリア

How can I weight the marker size in gscatter?

23 ビュー (過去 30 日間)
Christian
Christian 2016 年 10 月 11 日
コメント済み: Christian 2016 年 10 月 13 日
Hello,
I'm using gscatter to plot data by group. I have two vectors of size 100x1 that contain the x and y value, called x and y. I also have a vector of the same size, w, that contains weights. Now, I'd like to weigh the scatter dots by this matrix w. I tried something like
h = gscatter(x,y,gr,linspecer(length(b)-1),'.',30);
h.MarkerSize = w*30;
but it looks like Matlab only accepts a scalar for the marker size.
Thanks for your help.

採用された回答

Walter Roberson
Walter Roberson 2016 年 10 月 11 日
編集済み: Walter Roberson 2016 年 10 月 11 日
gscatter() creates lines, and lines can only have one marker size per line.
Consider using multiple scatter() calls instead, one per group (because scatter can only handle one marker shape per call)
  2 件のコメント
Christian
Christian 2016 年 10 月 13 日
Thanks, Walter. I wonder how I can then add the legend.
markersize = 30;
Col = linspecer(3);
hold on
for c = 1:3
scatter(x(gr==c),y(gr==c),markersize*w(gr==c),'MarkerEdgeColor',Col(c,:));
end
hold off
legend({'Gr1','Gr2','Gr3'});
This clearly doesn't work. It only gives me an empty framed box. Thanks for your ideas.
Christian
Christian 2016 年 10 月 13 日
I got it to work.
markersize = 30;
Col = linspecer(3);
h = [];
hold on
for c = 1:3
h = [h scatter(x(gr==c),y(gr==c),markersize*w(gr==c),'MarkerEdgeColor',Col(c,:))];
end
hold off
legend(h,{'Gr1','Gr2','Gr3'});

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeScatter Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by