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!