uistack on legend and axes objects

조회 수: 22 (최근 30일)
Cameron Brown
Cameron Brown 2016년 6월 14일
댓글: Cameron Brown 2016년 6월 27일
I have several legends which I would like to be stacked on top of the AXES objects in a figure window. I used to be able to use UISTACK to achieve this, but after upgrading to R2015b it no longer works.
Here is an example:
% make some data for plotting
x=randn(100,1);
y=2*x + randn(100,1);
z=x.^2 + randn(100,1);
% generate plots and legends
hFig=figure;
subplot(2,1,1)
plot(x,y,'bx','DisplayName','Linear')
hL1=legend('show');
subplot(2,1,2)
plot(x,z,'rx','DisplayName','Quadratic')
hL2=legend('show');
% move legends over the opposite plot to visualize stacking
hL1.Position=[0.79 0.32 0.2 0.2];
hL2.Position=[0.79 0.57 0.2 0.2];
% try to reorder stack to put legends on top
uistack([hL1 hL2],'top')
% display object stack order (legends have not been moved to top of stack)
disp(hFig.Children)
I want the stack to be: Legend, Legend, Axes, Axes However, after using UISTACK, the stack order is still: Legend, Axes, Legend, Axes
Is there a workaround to get the desired stack order?

답변 (1개)

Debarati Banerjee
Debarati Banerjee 2016년 6월 23일
Hi Cameron,
I made a few changes to the programme and I believe it is working now. Can you check this?
% make some data for plotting
x=randn(100,1);
y=2*x + randn(100,1);
z=x.^2 + randn(100,1);
% generate plots and legends
hFig=figure;
subplot(2,1,1)
plot(x,y,'bx','DisplayName','Linear')
hL1=legend('show');
subplot(2,1,2)
plot(x,z,'rx','DisplayName','Quadratic')
hL2=legend('show');
% move legends over the opposite plot to visualize stacking
% hL1.Position=[0.79 0.32 0.2 0.2];
% hL2.Position=[0.79 0.57 0.2 0.2];
set(hL1,'Position',[0.79 0.32 0.2 0.2]) %Struct field assignment overwrites a value with class "double", so not doing hL1.Position
set(hL2,'Position',[0.79 0.57 0.2 0.2])
% try to reorder stack to put legends on top
uistack([hL1 hL2],'top')
% display object stack order (legends have not been moved to top of stack)
disp(get(hFig,'Children'))
Cheers,
Debarati
  댓글 수: 1
Cameron Brown
Cameron Brown 2016년 6월 27일
This does not solve the problem I am referring to in my question above. The code I have provide runs without errors in MATLAB 2014b or later.
I guess you are running an earlier MATLAB version. The error you refer to: "Struct field assignment overwrites a value with class "double"" will not occur in later versions of MATLAB.
I have only had problems with setting the legend stacking in 2015b. I had no problems in 2014a and earlier.

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

카테고리

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