How to create nested legend

5 ビュー (過去 30 日間)
PRASHANT JHA
PRASHANT JHA 2023 年 8 月 21 日
コメント済み: Star Strider 2023 年 8 月 22 日
I have 20 entries in the plot, 5 under 4 heading, I want to categorise those 5 under their respective heading. I have attached the image. So, here I want to simply write h = 525 mm and its sub headings as w = 180, 150, 120, 90, 60 and then similarly for h = 450, so that my legend entry will look a little bit less clumsy.

採用された回答

Star Strider
Star Strider 2023 年 8 月 21 日
One option is to put each ‘h’ in a separate column —
h = 300 : 75 : 525;
w = 60 : 30 : 180;
[H,W] = ndgrid(h,w);
figure
hold on
for k1 = 1:size(H,1)
for k2 = 1:size(W,1)
plot(H(:,k1), H(1,k1)+W(:,k2), 'DisplayName',["h = "+H(k1,1)+", w = "+W(k2,1)])
end
end
hold off
legend('Location','best', 'NumColumns',numel(h))
.
  6 件のコメント
PRASHANT JHA
PRASHANT JHA 2023 年 8 月 22 日
yeah, i got it
i just tweaked the code a little bit here are there and got it perfectly
Star Strider
Star Strider 2023 年 8 月 22 日
Thank you!

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

その他の回答 (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