How to plot multiple scatter plot with regression line in one plot
조회 수: 8 (최근 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!
