xline for multiple axes in tiled layout

13 visualizaciones (últimos 30 días)
Biraj Khanal
Biraj Khanal el 14 de Mzo. de 2023
Comentada: Star Strider el 14 de Mzo. de 2023
How can I use xline or yline to make line in multiple axes of a tiled layout without having to write the lines for every tile?
I have the following code to plot multiple data in a tiled layout.
t = tiledlayout(1,2);
t1 = nexttile;
semilogy(x1,y1); hold on;
semilogy(x2,y2);
legend('x1','y1');
title('Data 1')
xline(3,'-')
xline(5,'-')
t2 = nexttile;
semilogy(xx1,yy1); hold on;
semilogy(xx2,yy2);
legend('xx1','xx2');
title('Data 2')
xline(3,'-')
xline(5,'-')
linkaxes([t1 t2],'x');
t1.XLim = [0 300];
While linkaxes works to set the limits, I am not sure how I can do this for the xline or yline functions.

Respuesta aceptada

Star Strider
Star Strider el 14 de Mzo. de 2023
The ‘ax’ argument to xline has to be a scalar axes handle, so passing a vector of axes handles to it fails. Each nexttile call creates a new axes, so subscript them and then use arrayfun, or a for loop —
t = tiledlayout(1,2);
tl(1) = nexttile;
plot(1:50, randn(1,50))
tl(2) = nexttile;
plot(1:40, randn(1,40))
arrayfun(@(ax)xline(ax,[3 5], 'r', 'LineWidth',2), tl)
.
  4 comentarios
Biraj Khanal
Biraj Khanal el 14 de Mzo. de 2023
Makes it clear. Thanks a lot!
Star Strider
Star Strider el 14 de Mzo. de 2023
As always, my pleasure!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Graphics Performance en Help Center y File Exchange.

Productos


Versión

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by