Edit tile properties like legend or title out of tiledlayout nextline lines
12 次查看(过去 30 天)
显示 更早的评论
I have a tiledlayout that I passed out of a function . I want to edit the properties of the axes in the tiled layout. Usually, it is done within the nexttile lines, But I am trying to do it after I finish creating the tiled layout.
t = tiledlayout (2,3) ;
t.Children has the axes array stored.
I tried editing the legend as following
legend(t.Children(6),'test')
And this does apply the legend to first axis from top left , i.e in t, the axis at (1,1) gets the legend .
However, if I add another line to change it or edit the legend text 'test' as following
legend(t.Children(6),'test2')
This now , somehow, does not apply to the same axis on which it did earlier. It would apply to a different axis , (1,2) to be exact. So every time I execute this line, it applies to the next tile in the layout.
Does this mean that the axes array changes everytime the line legend is executed?
How can I have lines with which I can change the legend or orther properties to the axes?
0 个评论
采纳的回答
Adam Danz
2023-3-23
编辑:Adam Danz
2023-3-23
I understand that you want to access a vector of TiledLayout axes and to keep put them in order.
If you're using MATLAB R2022b or later, you can use tilenum to get the tile index number for each tile. Then you can sort the vector of handles.
Demo:
Create tiledlayout and plots
tcl = tiledlayout(3,2);
for i = 1:6
nexttile
plot(rand(4))
end
Get axis handles and sort them in order
axh = findobj(tcl,'Type','axes');
axidx = tilenum(axh);
axh = axh(axidx);
Add legends using the problem shown in the question.
legend(axh(1))
title(axh(1)', '1')
legend(axh(2))
title(axh(2)', '2')
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Legend 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!