A problem with multiple columns in legend

39 ビュー (過去 30 日間)
Creatlee
Creatlee 2019 年 8 月 26 日
回答済み: Fred 2019 年 11 月 11 日
Hi all,
I just made the following lines, simply I cannot make a multiple column legend.
If anyone knows how to deal with this, i would be very thankful!
Thanks in advance.
figure
bar(randn(4))
[xx,yy] = legend({'a','b','c','d'}, 'box','off','NumColumns', 4)

採用された回答

Walter Roberson
Walter Roberson 2019 年 8 月 26 日
You cannot get multiple legend columns when you request the output of the legend icons.
[xx] = legend({'a','b','c','d'}, 'box','off','NumColumns', 4)
  2 件のコメント
Creatlee
Creatlee 2019 年 8 月 26 日
Thanks for the answer.
By the way, is there any way to have both outputs?
Or simply there is no need to have the second output when multiple columns are considered?
Walter Roberson
Walter Roberson 2019 年 8 月 26 日
The code actively chooses backwards compatibility if there is more than one output argument. That causes the legend to be built diffrently.

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

その他の回答 (1 件)

Fred
Fred 2019 年 11 月 11 日
But I need to increase the size of my MarkerSizes in my legend AND use two columns. Is there any way to do this?
%MWE of legend column and icon modification problem
close all, clearvars
x = 1:5; y = x.^2; %some data
figure
hold on
h = [scatter(x,5*x,200,'blue','filled','s'); ...
scatter(x,y,200,'red','filled','d')];
lgd = legend(h,{'Line','Quadratic'},'Location','Northwest');
lgd.NumColumns = 2; %want 2 columns for legend
figure
hold on
h = [scatter(x,5*x,200,'blue','filled','s'); ...
scatter(x,y,200,'red','filled','d')];
[lgd,icons] = legend(h,{'Line','Quadratic'},'Location','Northwest');
icons(3).Children.MarkerSize = 20; %want bigger MarkerSize for legend
icons(4).Children.MarkerSize = 20;
figure
hold on
h = [scatter(x,5*x,200,'blue','filled','s'); ...
scatter(x,y,200,'red','filled','d')];
[lgd,icons] = legend(h,{'Line','Quadratic'},'Location','Northwest');
icons(3).Children.MarkerSize = 20; %want bigger MarkerSize for legend
icons(4).Children.MarkerSize = 20;
lgd.NumColumns = 2; %want 2 columns for legend
% But I cannot have both. In fact, using [lgd,icons] makes 2 columns
% impossible

カテゴリ

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

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by