Kev1n91
Kev1n91

Reputation: 3673

Change the color of a surface plot from SFIT in MATLAB

I have four SFIT object that i plot with:

figure;
hold on;
plot(f1);
plot(f2);
plot(f3);
plot(f4);

This plots a 3D-Surface. However I would like to give each surface one unique color, like it is common with the plot function. Usually this is done by giving the paramter 'r' or something that indicates the color, like:

plot(f1,'r');

However, If I do this here i get the following error:

Error using plot No value was given for 'r'. Name-value pair arguments require a name followed by a value.

Error in sfit/plot>iParseInputs (line 231) p.parse( parameterValuePairs{:} );

Error in sfit/plot (line 44) [XY, Z, in, out, style, level, hParent] = iParseInputs( obj, varargin{:} );

This indicates that there must be a String to give, but which one ? I already tried something like 'Color' or 'LineColor' but these were not recognized

Simplifaction of the question: I want the planes that represent the fitted object to have one color. And each plane shall have a different one.

Upvotes: 0

Views: 781

Answers (1)

Wolfie
Wolfie

Reputation: 30047

From this link:

https://uk.mathworks.com/matlabcentral/answers/153208-how-can-i-make-the-contour-plot-of-an-sfit-object-resemble-the-plot-generated-by-the-contour-com

You could try

f1 = fit([x y], z, 'poly23');
ph = plot(f1, 'Style', 'Contour');
set(ph, 'Fill', 'off', 'LineColor', 'auto');

Documentation for set

https://uk.mathworks.com/help/matlab/ref/set.html


Edit

The above suggestion only displays a 2D plot, see this previous SO answer for the 3D case:

MATLAB - Plot multiple surface fits in one figure

The relevant code for you is:

figure; 
h = plot(f1); 
set(h(1),'FaceColor','r');

So the "magic word" which you were looking for is 'FaceColor', used in combination with set (mentioned above).

Upvotes: 1

Related Questions