Edit tile properties like legend or title out of tiledlayout nextline lines
9 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Biraj Khanal
el 23 de Mzo. de 2023
Comentada: Biraj Khanal
el 24 de Mzo. de 2023
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 comentarios
Respuesta aceptada
Adam Danz
el 23 de Mzo. de 2023
Editada: Adam Danz
el 23 de Mzo. de 2023
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')
Más respuestas (0)
Ver también
Categorías
Más información sobre Legend en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!