Why does legend goes to the back of the axes box in multiplots if you click it or move it with the mouse?
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
juan sanchez
el 27 de Nov. de 2021
Comentada: juan sanchez
el 29 de Nov. de 2021
Why does legend goes to the back of the axes box in multiplots if you click it or move it with the mouse? This happens specially in subplots or tiled plots (multiplots). I try to move the legend with the mouse somewhere else and immediate is behind the axes box completely concealed and I can not make it visible any more. Only if is on the side of the axes boxes within the gray zone but not inside the axes box where is desired to be.
3 comentarios
Respuesta aceptada
Adam Danz
el 29 de Nov. de 2021
We can't reproduce the problem without having a minimal working example (e.g. something you provide us that we can run on our end). The code you provided is a decent start but we also need the functions and variable values you're using.
However, I think this may be a problem with how you're creating legends. In your examples, the legends are created without using handles so the legend is assigned to current object which may not correspond to the intended axes.
Instead, use the DisplayName property to assign legend strings to objects and specify axis handles in the legend function.
% Assuming loglog produces 1 handle output,
loglog(nraw,sraw,'-.g','LineWidth',1, 'DisplayName', 'Spectra of Velocity');
grid on
ax = gca;
ax.FontSize = 17;
xlabel('${\rm{n }}\,(Hz)$', 'Interpreter', 'Latex');
ylabel('${S_n}$', 'Interpreter', 'Latex');
leg=legend(ax); % specify axis handle
leg.Interpreter='latex';
leg.FontSize = 7;
title(ax, ['Probe ',num2str(i_probe)]) % use axis handle
% If loglog outputs a vector of 4 handles,
h = loglog(nraw,sraw,'-.g','LineWidth',1); % store output handle
grid on
ax = gca;
ax.FontSize = 17;
xlabel('${\rm{n }}\,(Hz)$', 'Interpreter', 'Latex');
ylabel('${S_n}$', 'Interpreter', 'Latex');
leg=legend(h, 'Spectra of Velocity', '' '' ''); % specify axis handle and strings
leg.Interpreter='latex';
leg.FontSize = 7;
title(ax, ['Probe ',num2str(i_probe)]) % use axis handle
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!