Change of marker size and color of a fitted plot

조회 수: 11 (최근 30일)
Cheuk Yin Wong
Cheuk Yin Wong 2022년 5월 27일
댓글: Cheuk Yin Wong 2022년 5월 31일
x = T.Power_W;
y = T.Pressure_MPa;
f = fit(x,y,'power1')
%% plot
plot(f,x,y)
% annotation
xlabel('Power / W');
ylabel('Pressure / MPa');
set(gca,'fontsize',20)
legend('Raw data', 'Fitted function')
I have created a plot of some scattered data with a fitted power function. However, I cannot change the marker size by using plot(f,x,y,'MarkerSize',12). It shows 'Error using plot. Invalid color, marker, or line style.'. Could anyone please tell me how to change the color and the size of the marker? Thank you.

채택된 답변

dpb
dpb 2022년 5월 28일
The specialized version of plot for use with a fit object doesn't know about all the regular data plot function; it has only a set specific to it. <plot> is the specific version.
You'll have to save the line handles and use them;
>> hL=plot(f,x,y)
hL =
2×1 Line array:
Line (data)
Line (fitted curve)
>>
which shows you the first of the two is the data; the second the fitted line/curve which doesn't have any markers set.
hL(1).MarkersSize=12;
will work, but I'm guessing 12 is going to be too large...
  댓글 수: 4
dpb
dpb 2022년 5월 30일
Notice in the above where I plotted the fit it says "2x1 Line array" -- as you can see when you do this kind of plot, it puts two lines on the axes; as the above shows, the first is the raw data and the second is the fitted curve to that data.
You want to change the marker size of the data -- hence the first of the two lines on the graph.
Experiment -- try modifying things for the second line -- as I noted above, there are no markers on the fitted line by default so changing their size will have no visible effect -- but color would. Or, you could set a marker there and see how many points they use to calculate a smooth curve to draw.
See the doc for plot to read about line properties and about what the return value of a line handle is...
Cheuk Yin Wong
Cheuk Yin Wong 2022년 5월 31일
Thanks!

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

추가 답변 (0개)

카테고리

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

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by