Error when trying to create legend with stem plot

4 visualizaciones (últimos 30 días)
Sarah
Sarah el 25 de En. de 2013
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.

Respuesta aceptada

Walter Roberson
Walter Roberson el 25 de En. de 2013
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 comentarios
Sarah
Sarah el 26 de En. de 2013
I'll take a look. But check this out, I run this code:
stem(Tim,MetCond_N,'MarkerSize',0); hold on;
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;
set(gca,'YTick',[0:1:5])
set(gca,'YTickLabel',{'N','RW';'RH';'SW';'SM';'SS'})
legend({'N','RW','RH','SW','SM','SS'},'Location','NorthEast')
So I ran this, and the former error went away, but now I have this new error:
??? Error using ==> vertcat
CAT arguments dimensions are not consistent.
Any thoughts? Meanwhile, I'll investigate the markersize.
Sarah
Sarah el 26 de En. de 2013
Walter, thanks so much for your help! It works....I really appreciate it.

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by