Borrar filtros
Borrar filtros

A border/per​imeter/rec​tangle around the inset plot, in a subplot environment

36 visualizaciones (últimos 30 días)
Sim
Sim el 26 de Jun. de 2024 a las 14:09
Comentada: Sim el 26 de Jun. de 2024 a las 14:58
In the following subplot environment, how can I draw a red border/perimeter/rectangle around/wrapping the inset plot?
fig = figure;
for i = 1 : 6
subplot(3,2,i)
scatter(rand(1,10),rand(1,10))
end
axes(fig,'Position',[.1 .2 .2 .2])
plot(1:5,rand(1,5))

Respuesta aceptada

Voss
Voss el 26 de Jun. de 2024 a las 14:47
Here are a couple of options:
fig = figure;
for i = 1 : 6
subplot(3,2,i)
scatter(rand(1,10),rand(1,10))
end
ax = axes(fig, ...
'Position',[0.02 0.12 0.29 0.29], ...
'Visible','off', ...
'ClippingStyle','rectangle', ...
'XLim',[-0.01 1.01], ...
'YLim',[-0.01 1.01], ...
'XTick',[], ...
'YTick',[]);
line(ax, ...
'XData',[0 0 1 1 0], ...
'YData',[0 1 1 0 0], ...
'Color','r', ...
'LineWidth',3, ...
'LineJoin','miter', ...
'Clipping','off')
axes(fig,'Position',[0.1 0.2 0.2 0.2])
plot(1:5,rand(1,5))
xlabel('xlabel')
ylabel('ylabel')
fig = figure;
for i = 1 : 6
subplot(3,2,i)
scatter(rand(1,10),rand(1,10))
end
axes(fig,'Position',[0.02 0.12 0.29 0.29], ...
'Box','on', ...
'XTick',[], ...
'YTick',[], ...
'XColor','r', ...
'YColor','r', ...
'LineWidth',3)
axes(fig,'Position',[0.1 0.2 0.2 0.2])
plot(1:5,rand(1,5))
xlabel('xlabel')
ylabel('ylabel')

Más respuestas (1)

Sim
Sim el 26 de Jun. de 2024 a las 14:50
Editada: Sim el 26 de Jun. de 2024 a las 14:58
Got it, with the Control Axes Layout options!
fig = figure;
for i = 1 : 6
subplot(3,2,i)
scatter(rand(1,10),rand(1,10))
end
ax = axes(fig,'Position',[.1 .2 .2 .2]);
plot(1:5,rand(1,5))
xlabel('my xlabel')
ylabel('my ylabel')
annotation("rectangle",ax.OuterPosition,Color="red",LineWidth=2)

Community Treasure Hunt

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

Start Hunting!

Translated by