필터 지우기
필터 지우기

Why doesn't my code to insert and format a legend work in 2014b?

조회 수: 1 (최근 30일)
Brett Mather
Brett Mather 2015년 2월 17일
편집: Brett Mather 2015년 2월 17일
I have read that the legend no longer has children in 2014b, and that I should use the output arguments from the legend function to get the handles for these objects (<http://www.mathworks.com/help/matlab/graphics_transition/why-is-the-children-property-empty-for-some-objects.html)>.
However, the legend function doesn't seem to work properly with these output agruments. I have put together some code to show my problems with the legend output arguments and formatting.
clear all
close all
clc
%%%%%creating 1st figure
f=figure;
ax=axes;
p1=plot(1:10,1:10);
hold all
p2=plot(10:-1:1,1:10);
%%this line returns a warning:
[mylegend1,legend_items1]= legend(ax,{'a','b'}, 'FontSize', 4,'Orientation','horizontal','Units','pixels','Interpreter', 'none');
% Warning: Error updating Legend. Following is the chain of causes of the error:
%
% Attempted to access lpos(3); index out of bounds because numel(lpos)=2.
%
% > In defaulterrorcallback at 12
% In C:\Program Files\MATLAB\R2014b\toolbox\matlab\scribe\private\legendHGUsingMATLABClasses.p>find_legend_info at 382
% In C:\Program Files\MATLAB\R2014b\toolbox\matlab\scribe\private\legendHGUsingMATLABClasses.p>legendHGUsingMATLABClasses at 251
% In legend at 118
%%%%%creating 2nd figure
f2=figure;
ax2=axes;
p3=plot(1:10,1:10);
hold all
p4=plot(10:-1:1,1:10);
%%by removing the legend_items output argument there is no warning:
mylegend2= legend(ax2,{'a','b'}, 'FontSize', 4,'Orientation','horizontal','Units','pixels','Interpreter', 'none');
%%%%%creating 3rd figure
f3=figure;
ax3=axes;
p5=plot(1:10,1:10);
hold all
p6=plot(10:-1:1,1:10);
%multiple output arguments returns no warnings without the property changes
%that I need
[mylegend3,legend_items3]= legend(ax3,{'a','b'});
%attempting to set the properties after the fact doesn't work as expected;
%especially seemsto have trouble with Orientation 'horizontal'
set(mylegend3,'FontSize', 4,'Orientation','horizontal','Units','pixels','Interpreter', 'none')

답변 (0개)

카테고리

Help CenterFile Exchange에서 Legend에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by