How can I change marker size when plotting?

252 ビュー (過去 30 日間)
Nicholas Pfaff
Nicholas Pfaff 2018 年 7 月 9 日
コメント済み: dpb 2018 年 7 月 10 日
I want to change the marker size and line width for my following plot:
function [fitresult, gof] = createFit(diameter, time)
%CREATEFIT(DIAMETER,TIME)
% Create a fit.
%
% Data for 'Raw Data' fit:
% X Input : diameter
% Y Output: time
%%Fit: 'Raw Data'.
[xData, yData] = prepareCurveData( diameter, time );
% Set up fittype and options.
ft = fittype( 'power1' );
opts = fitoptions( 'Method', 'NonlinearLeastSquares' );
opts.Display = 'Off';
opts.StartPoint = [155.522818446907 -1.88432816467686];
% Fit model to data.
[fitresult, gof] = fit( xData, yData, ft, opts );
% Plot fit with data.
figure( 'Name', 'Raw Data' );
h = plot( fitresult,'b', xData, yData, '.k', 'MarkerSize',10); %Works without 'MarkerSize',10 but not with it
legend( h, 'time vs. diameter', 'Raw Data', 'Location', 'NorthEast' );
% Label axes
xlabel diameter
ylabel time
grid on
hold on;
axis([0 22 0 41]);

採用された回答

dpb
dpb 2018 年 7 月 9 日
編集済み: dpb 2018 年 7 月 10 日
h = plot( fitresult,'b', xData, yData, '.k', 'MarkerSize',10);
Looks like you've exceeded the smarts of the enhanced plot command; granted it looks like it might should work but I don't see that the extra named parameters are actually listed in the doc.
I'm guessing you'll need to go at it in two steps; either separate the fit and the data plots initially or
hL=plot(fitresult,'b', xData, yData, '.k');
hL(1).'MarkerSize'=10;
I'm guessing will work....might be worth a support request unless somebody sees something I missed. Complexity has its paybacks in adding all these objects and so on--the interfaces just get more and more convoluted.
Addendum Test above; does work with the correction that it's hL(1) that's the data line, not hL(2) I had presumed first based on order in the argument list.
Worth a query to TMW on whether the original should work or not; I'm not positive altho I'm guessing they'll say "no"...
  1 件のコメント
Nicholas Pfaff
Nicholas Pfaff 2018 年 7 月 10 日
Thank you! It worked with
h(1).MarkerSize = 10;

サインインしてコメントする。

その他の回答 (1 件)

Image Analyst
Image Analyst 2018 年 7 月 10 日
編集済み: Image Analyst 2018 年 7 月 10 日
When you call
h = plot( fitresult,'b', xData, yData, '.k', 'MarkerSize',10);
why can't you just pass in a variable instead of 10? And pass in the 'LineWidth' property too.
markerSize = randi([5 25], 1,1); % Whatever you want...
lineWidth = 3; % Whatever...
h = plot(fitresult,'b', xData, yData, 'k.-', ...
'MarkerSize', markerSize, ...
'LineWidth', lineWidth);
  4 件のコメント
Image Analyst
Image Analyst 2018 年 7 月 10 日
I guess I never have this problem because I don't plot multiple curves in one call to plot(). I just use multiple calls to plot() where each one plots one curve.
dpb
dpb 2018 年 7 月 10 日
Yes, much cleaner syntax that way; this is all a fignewton created by the attempt to overload plot with all these extra features for other objects besides just x, y plots.
They've created a monster by going down this road from which now there probably is no return but also no way to go forward cleanly.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeInterpolation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by