How to plot multiple scatter plot with regression line in one plot

20 Ansichten (letzte 30 Tage)
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

Akzeptierte Antwort

Voss
Voss am 2 Nov. 2022
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

Weitere Antworten (0)

Kategorien

Mehr zu Graphics Object Identification finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by