How to plot multiple scatter plot with regression line in one plot
27 ビュー (過去 30 日間)
古いコメントを表示
I am trying to show multiple scatter plots with regression line in one plot with the hold on function. But I get the error message
"Assigning to 2 elements using a simple assignment statement is not supported. Consider using comma-separated list
assignment." What do I do wrong?
scatter(all_subs_data(:,4),all_subs_data(:,144),"filled","o","MarkerFaceColor","r","SizeData",100, 'MarkerFaceAlpha',.1)
h1 = lsline
h1.Color = 'r'
h1.LineWidth = 3.0000
hold on
scatter(all_subs_data(:,5),all_subs_data(:,143),"filled","o","MarkerFaceColor","b","SizeData",100, 'MarkerFaceAlpha',.1)
h2 = lsline
h2.Color = 'b'
h2.LineWidth = 3.0000
hold off
0 件のコメント
採用された回答
Voss
2022 年 11 月 2 日
Note that "lsline superimposes a least-squares line on each scatter plot in the current axes".
That is, the second call to lsline returns two lines, since there are two scatter plots in the axes at that point in time.
To avoid creating redundant lines, make both scatter plots first, call lsline, and then set the properties of each line object returned:
all_subs_data = rand(10,150); % random data
scatter(all_subs_data(:,4),all_subs_data(:,144),"filled","o","MarkerFaceColor","r","SizeData",100, 'MarkerFaceAlpha',.1)
hold on
scatter(all_subs_data(:,5),all_subs_data(:,143),"filled","o","MarkerFaceColor","b","SizeData",100, 'MarkerFaceAlpha',.1)
h = lsline();
h(1).Color = 'r';
h(1).LineWidth = 3.0000;
h(2).Color = 'b';
h(2).LineWidth = 3.0000;
hold off
その他の回答 (0 件)
参考
カテゴリ
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!