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

采纳的回答

Voss
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 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