Error when trying to create legend with stem plot
조회 수: 3 (최근 30일)
이전 댓글 표시
I receive the following error when plotting a legend with my stem plot:
??? Error using ==> feval
Value must be finite and greater than zero
Error in ==> scribe.legend.methods>build_legendinfo_component at
497
lich=feval(lic.ConstructorName,'Parent',double(p),lic.PVPairs{:});
Error in ==> scribe.legend.methods>build_legendinfo_component at
506
build_legendinfo_component(lich,gcomp(k),tx,ty);
Error in ==> scribe.legend.methods>build_legendinfo_token at 461
build_legendinfo_component(gh,gcomp(k),tx,ty);
Error in ==> scribe.legend.methods at 17
feval(args{:});
Error in ==> scribe.legend.methods>create_legend_items at 1500
methods(h,'build_legendinfo_token',tokenhandle(end),li,tokenx,tokeny);
Error in ==> scribe.legend.methods at 17
feval(args{:});
Error in ==> scribe.legend.legend at 115
methods(h,'create_legend_items',children);
Error in ==> legend>make_legend at 389
lh=scribe.legend(ha,orient,location,position,children,listen,strings,propargs{:});
Error in ==> legend at 287
[h,msg] = make_legend(ha,varargin(arg:end));
Here is the code that I use to create the legend:
stem(Tim,MetCond_RW,'MarkerSize',0,'Color','c');
stem(Tim,MetCond_RH,'MarkerSize',0,'Color','b');
stem(Tim,MetCond_SW,'MarkerSize',0,'Color','m');
stem(Tim,MetCond_SM,'MarkerSize',0,'Color','g');
stem(Tim,MetCond_SS,'MarkerSize',0,'Color','r'); hold off;
datetick('x','mm/dd');
xlim([datenum('2012/01/15 00:00:00') datenum('2012/02/05 00:00:00')]); grid on
grid on;
set(gca,'YTick',[0:1:5])
set(gca,'YTickLabel',{'N';'RW';'RH';'SW';'SM';'SS'})
%set(gca,'YTickLabel',{0; 1; 2; 3; 4; 5; 6})
legend('N','RW','RH','SW','SM','SS',2);
Here, N is 0, RW is 1, and so on and so forth. I defined these values through a MATLAB script that was called earlier. Is this because I have made the value of N to be 0? I believe that the problem persists even if I remove N. Can someone help me out here? I've spent a lot of time on this and don't really know how to proceed. Thanks for your time.
댓글 수: 0
채택된 답변
Walter Roberson
2013년 1월 25일
Is 2 intended to be a location? If so, then change it to 'Location', 'NorthWest'
It is also recommended to avoid confusion between properties and legend entries by passing the legend entries in a cell array:
legend( {'N', 'RW','RH','SW','SM','SS'}, 'Location', 'NorthWest' )
댓글 수: 9
추가 답변 (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!