Borrar filtros
Borrar filtros

Matlab 2014b: Copying just the legend from existing figure into subplot

17 visualizaciones (últimos 30 días)
Hi there,
I'm looking for how to get the legend from an existing saved figure and load it as the legend in a figure of subplots.
In 2013 I used to be able to do:
h1 = hgload('file.fig');
leg_ax = findobj(h1,'type','axes','Tag','legend','-not','Tag','Colorbar');
s6 = subplot(2,3,3);
copyobj(leg_ax,get(s6,'Parent'));
Thanks, Ashley

Respuesta aceptada

Matt J
Matt J el 19 de Nov. de 2014
Editada: Matt J el 19 de Nov. de 2014
One way is to save and reuse just the legend object itself, e.g.,
plot(1:5,2:6,1:5,0:4);
hleg=legend('First Line', 'Second Line');
save tst hleg
clear hleg
load tst hleg
figure;
s6 = subplot(2,3,3);
plot(10:10:50,(2:6).^2,10:10:50,(0:4).^2);
legend(hleg.String{:})
  3 comentarios
Matt J
Matt J el 19 de Nov. de 2014
h1=hgload(...)
hleg=findobj(h1,'Type','Legend');
s6 = subplot(2,3,3);
legend(hleg.String{:});
Ashley Penna
Ashley Penna el 19 de Nov. de 2014
Excellent, that worked! Thanks for your help, Matt.

Iniciar sesión para comentar.

Más respuestas (1)

Azzi Abdelmalek
Azzi Abdelmalek el 19 de Nov. de 2014
h1 = hgload('file.fig');
leg_ax = findobj(h1,'type','axes','Tag','legend','-not','Tag','Colorbar');
figure
s6 = subplot(2,3,3);
copyobj(leg_ax,get(s6,'Parent'));
  2 comentarios
Ashley Penna
Ashley Penna el 19 de Nov. de 2014
In 2013 the "leg_ax" line no longer works since a legend isn't an axes any longer.
Azzi Abdelmalek
Azzi Abdelmalek el 19 de Nov. de 2014
The handles can not be used if the object is deleted

Iniciar sesión para comentar.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by