Plot legend goes behing plot axes when using tiledlayout

12 ビュー (過去 30 日間)
Jann
Jann 2024 年 6 月 4 日
コメント済み: Jann 2024 年 6 月 5 日
I am generating several plots with legends on one figure using tiledlayout(). While the plot looks correct, the legends disappear behind the axes when I try to move them. The issue appears to be the same as described in this question, although I did not have any success with the fix:
The minimimum code that produces the issue is below. I get the same results when I omit the object handles.
t = tiledlayout(2, 1);
ax1 = nexttile(t);
pt1 = plot(ax1, 0:10, 0:10);
lg1 = legend(ax1, 'Plot 1');
ax2 = nexttile(t);
pt2 = plot(ax2, 0:10, 0:10);
lg2 = legend(ax2, 'Plot 2');
  2 件のコメント
Joe Vinciguerra
Joe Vinciguerra 2024 年 6 月 4 日
FWIW, I am unable to reproduce this in 2023b and 2024a. I don't have 2023a installed.
Jann
Jann 2024 年 6 月 5 日
Updating to 2023b seems to have resolved the issue.

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

回答 (1 件)

Athanasios Paraskevopoulos
Athanasios Paraskevopoulos 2024 年 6 月 4 日
The issue you are experiencing with legends disappearing behind the axes when moved in a tiledlayout can be addressed by setting the 'AutoUpdate' property of the legends to 'off'. This prevents the legends from updating automatically and helps maintain their visibility when moved.
t = tiledlayout(2, 1);
% First tile
ax1 = nexttile(t);
pt1 = plot(ax1, 0:10, 0:10);
lg1 = legend(ax1, 'Plot 1');
set(lg1, 'AutoUpdate', 'off'); % Prevents auto-updating of legend
% Second tile
ax2 = nexttile(t);
pt2 = plot(ax2, 0:10, 0:10);
lg2 = legend(ax2, 'Plot 2');
set(lg2, 'AutoUpdate', 'off'); % Prevents auto-updating of legend
  1 件のコメント
Jann
Jann 2024 年 6 月 4 日
Unfortunately, this did not resolve the issue.

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

カテゴリ

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

製品


リリース

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by