フィルターのクリア

legend properties of columnlegend

12 ビュー (過去 30 日間)
Anna S
Anna S 2020 年 1 月 8 日
編集済み: Adam Danz 2020 年 1 月 8 日
Hi :)
I would like to use columnlegend to make my legend appear nicely. Since I need to change the fontsize and -weight, I used the following code:
h = columnlegend(2, p2, 'location', 'southoutside');
h.FontSize = 16;
h.FontWeight = 'bold'
h
where p2 contains the strings for the legend.
when I look at the properties of h, they changed to the desired values, but they do not change in the plot.
The same happens, when I enter it directly to the legend command:
h = columnlegend(2, p2, 'location', 'southoutside','FontSize',16,'FontWeight','bold');
timeline_ADVslt_winter.png
The image shows my problem. I am using R2016b.
Does someone know how to solve this?

採用された回答

Adam Danz
Adam Danz 2020 年 1 月 8 日
編集済み: Adam Danz 2020 年 1 月 8 日
The problem
The file exchange function columnlegend() (started in 04/2010, last updated 09/2016) calls legend() with multiple outputs,
[legend_h,object_h,plot_h,text_strings] = legend(str);
Note: This syntax is not recommended and creates a legend that does not support
all graphics features. Use the l = legend(__) syntax to return the legend object
and set Legend Properties instead.
Toward the top of Matlab's legend code, a flag named version is set to on when the number of output arguments is greater than one. When version is on, a legacy version of the legend is created by this function which we do not have access to
leg.doPostSetup(version_flag);
Solution
Starting in r2018a, you can set the NumColumns property of Matlab's legend() function making the columnlegend() function obsolete (thanks to the original author, Simon Henin, for inspiring that change in Matlab).
legend(. . ., 'NumColumns', 2)
For Matlab releases prior to r2018a, use the 2nd output of columnlegend(), isolate the legend string handles, and change the text properties.
[h, object_h] = columnlegend(. . .);
% Set spacing (This will not change font size or weight)
set(h, 'FontSize', 16, 'FontWeight', 'bold')
% Get text handles
legTextHand = object_h(strcmpi(get(object_h,'type'),'text'));
% Change fontsize and weight
set(legTextHand,'FontSize',16,'FontWeight','bold')
  2 件のコメント
Anna S
Anna S 2020 年 1 月 8 日
I have also tried something similar, but your solution works!
Thank you a lot!
Funnyly, I need to give the information twice to get it work:
[h,object_h] = columnlegend(2, p2, 'location', 'southoutside');
h.FontSize = 16;
h.FontWeight = 'bold'
% Get text handles
legTextHand = object_h(strcmpi(get(object_h,'type'),'text'));
set(legTextHand,'FontSize',16,'FontWeight','bold')
But at least it does what it should :)))
Adam Danz
Adam Danz 2020 年 1 月 8 日
Ah.... this section below sets the spacing
h.FontSize = 16;
h.FontWeight = 'bold'
while this section below sets the fontsize etc.
set(legTextHand,'FontSize',16,'FontWeight','bold')
Glad I could help.

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by