Can I plot a cfit object and specify the LineSpec using name/value pairs?

조회 수: 27 (최근 30일)
Emily
Emily 2019년 8월 6일
댓글: Emily 2019년 8월 7일
I am trying out several fits of data. I want to display the different fits in different colors. There are an indeterminate number of fits, and I want my data to be useful to somebody with limited color vision, so want to use Parula for the colors of the lines. According to the documentation I can plot a cfit object with:
plot(cfit,FitLineSpec,x,y,DataLineSpec)
This works if I use '-k' for the FitLineSpec, but doesn't work if I use 'color','k'.
Minimal example:
X = 1:10;
Y = X.^2;
[fitobject,foErr]=fit(X',Y','poly1');
figure; plot(x,y,'color','c'); % This plots the data in cyan
hold on;
plot(fitobject, 'k-'); % This works fine and makes a black line, but if I want a color not defined by a letter, I need name/value pairs:
plot(fitobject, 'color','k') % This doesn't work, giving the error
Error using cfit/plot>parseinput (line 335)
Must specify both XDATA and YDATA
It also doesn't work to use
plot(fitobject, 'color','k', X,Y,'color','c')
which gives a slightly different parsing error for cfit.
My question is, can I use name/value pairs for specifying the LineSpec when plotting a cfit object, and if so, how?
Thanks,
Emily
p.s. This question submitted itself unexpectedly and now I can't seem to edit the tags. I'm using Matlab R2017b.
  댓글 수: 1
dpb
dpb 2019년 8월 6일
Yeah, for some reason TMW seems to have removed the facility to edit Tags...even I couldn't seem to do so last I tried (but I've not given it another attempt since, either). Don't understand that, either, do I...

댓글을 달려면 로그인하십시오.

채택된 답변

dpb
dpb 2019년 8월 6일
편집: dpb 2019년 8월 6일
No, TMW didn't implement the named parameter interface in the cfit class plot() method. Another example of not following the general pattern going forward and most irritating, agreed. It's worthy of a "Quality of Implementation" bug report imo.
What you do is save the line handles returned and use those to apply the remaining linestyle/colors/etc. desired for each line. PIT[proverbial]A[ppendage], but what needs must do.
  댓글 수: 1
Emily
Emily 2019년 8월 7일
Thanks dpb,
I appreciate your help! That works for me. For others who might want to do this here's the explicit example:
cmp = colormap(parula(numberFits)) % Gives a numberFits by 3 matrix of RGB values
X = 1:10;
Y = X.^2;
figure; plot(X,Y,'color','c'); % This plots the data in cyan
hold on;
for fitnumber = 1:numberFits
[fitobject,foErr]=fit(X',Y','poly1'); % You would change something about the fit with each cycle of loop)
FitHandle=plot(fitobject);
set(FitHandle,'color',cmp(fitnumber,:));
end

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Graphics Performance에 대해 자세히 알아보기

태그

제품


릴리스

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by