HandleVisibility using the fit function
조회 수: 13 (최근 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!