Columns (with different column sizes) in plotlegend

16 ビュー (過去 30 日間)
Luke
Luke 2022 年 12 月 20 日
編集済み: Luke 2022 年 12 月 21 日
Dear Matlab community,
I would like to have a three columned legend as shown in this picture:
I tried Legend Location and Number of Columns, but unfortunately the result with three columns isn’t grouped as I need to (as you can see).
Do you have any advice how to group the columns differently? I use R2019b.
Best wishes
Lukas

採用された回答

Voss
Voss 2022 年 12 月 20 日
I don't know of a way to do that by setting legend properties, but you can create "dummy" lines that don't appear in you plot but do hold space in the legend.
Here's an example of plotting 16 lines in a loop and after the 5th and 10th lines are plotted creating the "dummy" lines for the legend:
hold on
for ii = 1:16
plot(1:10,rand(1,10));
if ii == 5 || ii == 10
plot(NaN,NaN,'LineStyle','none','DisplayName','')
end
end
legend('NumColumns',3)
I imagine that you should be able to do the same in your code by inserting plot(NaN,NaN,'LineStyle','none','DisplayName','') in the right two places.
  1 件のコメント
Luke
Luke 2022 年 12 月 21 日
編集済み: Luke 2022 年 12 月 21 日
Thank you, I didn't know about the "dummy" line option.

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by