Why the legend shows error ?
4 次查看(过去 30 天)
显示 更早的评论
I'm getting the following error with the code:
figure;
hold on
[ax,h1,h2]=plotyy(distance,G.*(distance.^-2),distance,G);
set(ax,{'ycolor'},{'k';'k'},'Fontsize',16);
% set(ax(2),'ytick',[0:0.2:1.4],'fontsize',16);
plot(distance,(distance.^-2),'k--','LineWidth',2);
h1.Color = 'b';
h2.Color = 'r';
h1.LineWidth=2;
h2.LineWidth=2;
xlabel('\fontname{Arial}Range(m)');
set(gca,'xlim',[0 200],'xtick',[0:50:200]);
ylabel('\fontname{Arial}Backscattering signal intensity(unit)');
set(gca,'ylim',[0.*10.^-3 1.5.*10.^-3],'ytick',[0:.5:1.5].*10.^-3);
set(gca,'color','w','Fontsize',16,'LineWidth',1,'Fontweight','normal');
set(gca,'box','on','boxstyle','full','Fontname','Arial','Fontsmoothing','on');
set(gca,'xgrid','on','ygrid','on','gridcolor','k');
yyaxis right
ylabel('Overlap function value');
set(gca,'ylim',[0 1.4],'ytick',[0:0.2:1.4]);
set(gca,'Ycolor','k');
legend('Signal intensity (unit)','1/z^2','Overlap function','fontsize',12,'location','Northeast','orientation','vertical','numcolumns',1,...
'box','on');
leg.ItemTokenSize = [15,18];
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0.3 0.3 .3 .45],'innerposition',[.11 .15 .15 .75]);
How can wee solve it?
2 个评论
回答(2 个)
dpb
2023-1-19
移动:dpb
2023-1-19
We don't have the data to try to reproduce, but I expect the problem is you're trying to mix the old plotyy and the new yyaxis syntax and they don't play well together.
Stick with one or the other and it'll probably work....if use all yyaxis calls, you'll get a legend object created by default; if you were then to assign the 'DisplayName' property to the line when plotted, they would show up automagically; then you could retrieve the legend handle (it's a child of the figure, not the axes) and make whatever global changes wanted there.
Walter Roberson
2023-1-20
移动:Walter Roberson
2023-1-20
legend({'Signal intensity (unit)','1/z^2','Overlap function'}, 'fontsize', 12, 'location', 'Northeast', 'orientation', 'vertical', 'numcolumns', 1,...
'box', 'on');
but I wonde which MATLAB version you are using? You might possibly be using a version too early to support multiple columns.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Legend 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!