Why does legend goes to the back of the axes box in multiplots if you click it or move it with the mouse?
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Adam Danz
2021-11-29
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
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Legend 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!