uistack on legend and axes objects
조회 수: 26 (최근 30일)
이전 댓글 표시
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?
댓글 수: 0
답변 (1개)
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Legend에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!