Problem with 2014b for replotting with multiple legends in plotyy chart

조회 수: 1 (최근 30일)
Art Kotz
Art Kotz 2014년 12월 11일
답변: Art Kotz 2015년 6월 16일
I am trying to update a chart created with plotyy that uses two legend boxes for the two y-axes. I can create the chart, but when I replot the chart (normally with new data or with a different number of traces), I get the following error:
Error using legend (line 120)
'LayoutManager' is already defined as a property.
This code replicates the error (note: this worked fine in 2013a, but fails in 2014b)
% setup and initial chart
x = 1:10;
y1 = [1:10;0:9];
y2 = [20:-2:2];
figure;
[AX, H1, H2] = plotyy(x,y1,x,y2);
legend(AX(1), 'y1', 'Location', 'NorthWest');
legend(AX(2), 'y2', 'Location', 'NorthEast');
% replot using the same commands - this first part works as expected
[AX, H1, H2] = plotyy(x,y1,x,y2);
legend(AX(1), 'y1', 'Location', 'NorthWest');
% This last line fails with the error noted above
legend(AX(2), 'y2', 'Location', 'NorthEast');
Any thoughts?
  댓글 수: 1
Art Kotz
Art Kotz 2015년 6월 10일
Still no answers ... Is there a better way to put two legends for different axes on a chart as described above?

댓글을 달려면 로그인하십시오.

채택된 답변

Art Kotz
Art Kotz 2015년 6월 11일
I submitted the problem to the support group at The Mathworks and got a response that works. If I use "clf" (clear figure) before the second call to plotyy, the replot works fine. This serves my needs and will let me deploy some programs under 2014b.
In the response, I was told that the problem has been fixed in the 2015b prerelease, so hopefully this will not be an issue when the full release comes out.

추가 답변 (1개)

Art Kotz
Art Kotz 2015년 6월 16일
Update: The previous answer works for the problem statement I submitted. However, in a GUIDE application, you can't clear the bounding figure without crashing your application. In addition, if you have more than one axes object in your application, using clf on one of the axes causes an immediate crash of Matlab (not just the application, but the Matlab session itself).
A workaround proposed by Ryan Povall (thanks!) is to delete the axes object and recreate it. The following sequence of statements does this while preserving the position of the axes object. Hopefully it will be unnecessary in 2015b, but in the meantime this gets the job done for my applications ...
sUnits = get(handles.MyChart, 'Units');
pos = get(handles.MyChart, 'Position');
delete(handles.MyChart);
handles.MyChart = axes('Units', sUnits, 'Position', pos);

카테고리

Help CenterFile Exchange에서 Two y-axis에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by