HandleVisibility using the fit function
15 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (3 件)
Sean de Wolski
2011 年 12 月 27 日
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 件のコメント
Walter Roberson
2011 年 12 月 27 日
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 件のコメント
参考
カテゴリ
Help Center および File Exchange で Legend についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!