HandleVisibility using the fit function
15 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I am fitting a surface to three dimensional data as follows:
f=fit([x,y],z,'poly22');
I want to plot the x,y,z data points as well as the surface. I am doing that as follows:
plot(f,[x,y],z);
However, I only want the legend to be for the data points, not the fitted surface. I can't figure out where to put the
'HandleVisibility','off'
so that the surface does not show up in the legend. Everywhere I try to put it, I get an error.
Any suggestions?
Thanks.
0 Kommentare
Antworten (3)
Sean de Wolski
am 27 Dez. 2011
So you only want the legend to apply to some parts of the plot? Try feeding the handles you want the legend to contain into legend:
figure; hold on
H(1) = plot(1:10,1:10,'b-');
H(2) = plot(1:10,(1:10)+50,'k-');
H(3) = plot(1:10,(1:10).^2,'r-');
legend(H([1 3]),'1:10','(1:10).^2')
0 Kommentare
Walter Roberson
am 27 Dez. 2011
I believe you probably want something like
plot([x,y],f,[x,y],z);
Otherwise you are feeding an odd number of inputs to plot(), which would cause one of the pairs of data to use sequential coordinates rather than the coordinate system you have established.
Instead of working with handle visibility to control legends, you should be working with IconDisplayStyle. See http://www.mathworks.com/help/techdoc/creating_plots/braliom.html#bram7nu
When plot()'ing x-y pairs, if y is a row vector, then 1 lineseries object will be generated, and otherwise as the number of lineseries objects will be the same as the number of columns in y. If you assign the output of plot() to a variable to get the handles, this calculation allows you to figure out how many of the handles relate to each of the x-y pairs.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Legend finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!