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
Adam Danz 2021 年 11 月 28 日
A minimal working example would be helpful.
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
  1 件のコメント
juan sanchez
juan sanchez 2021 年 11 月 29 日
Thank you very much for your explanation. It helps very much how to deal these kind of problems.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLegend についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by