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
juan sanchez
juan sanchez 2021년 11월 29일
편집: Adam Danz 2021년 11월 29일
Thank you, I am attaching this example and image to explain what is happenig. First, if I try to move the legend with the mouse, the first tile gets all distorted and the legend is concealed behind the axes box and there is no way I can bring it back on top of the axes box. I am using Matlab R2021a. Thank you
[nraw,sraw,navg,savg] = Spectra(V.*0.3048,[],Samp_Freq,'dim',10);
loglog(nraw,sraw,'-.g','LineWidth',1);
grid on
ax = gca;
ax.FontSize = 17;
xlabel('${\rm{n }}\,(Hz)$', 'Interpreter', 'Latex');
ylabel('${S_n}$', 'Interpreter', 'Latex');
leg=legend('Spectra of velocity', '', '', '');
leg.Interpreter='latex';
leg.FontSize = 7;
title(['Probe ',num2str(i_probe)])

댓글을 달려면 로그인하십시오.

채택된 답변

Adam Danz
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 CenterFile Exchange에서 Legend에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by