How to make size of legend window on a figure window as small as we desire?????

38 ビュー (過去 30 日間)
Sadiq Akbar
Sadiq Akbar 2022 年 7 月 1 日
コメント済み: Sadiq Akbar 2022 年 7 月 4 日
I have drawn my plot having a legend window on it. The legend is coming over the graph lines. I want to make size of the legend window as small as I want so that the graph is completely visible. How to do it? My figure is attached here.
  1 件のコメント
Simon Chan
Simon Chan 2022 年 7 月 1 日
How about putting the legend outiside by setting the legend location?

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

採用された回答

Chunru
Chunru 2022 年 7 月 1 日
編集済み: Chunru 2022 年 7 月 1 日
openfig("fitness2snAll.fig");
figure
openfig("fitness2snAll.fig");
h = legend
h =
Legend (\bf Noise Free, \bf 35dB, \bf 45dB, 55dB, 65dB) with properties: String: {'\bf Noise Free' '\bf 35dB' '\bf 45dB' '55dB' '65dB'} Location: 'northeast' Orientation: 'vertical' FontSize: 9 Position: [0.5254 0.6128 0.3500 0.2727] Units: 'normalized' Show all properties
% Try to adjust the position of the legend
% But the pos may be modified by MATLAB
pos = h.Position;
pos(1:2) = [0.5 0.35];
pos(3:4) = 0.5*pos(3:4)
pos = 1×4
0.5000 0.3500 0.1750 0.1364
h.Position = pos
h =
Legend (\bf Noise Free, \bf 35dB, \bf 45dB, 55dB, 65dB) with properties: String: {'\bf Noise Free' '\bf 35dB' '\bf 45dB' '55dB' '65dB'} Location: 'none' Orientation: 'vertical' FontSize: 9 Position: [0.4125 0.2818 0.3500 0.2727] Units: 'normalized' Show all properties
figure
openfig("fitness2snAll.fig");
h = legend
h =
Legend (\bf Noise Free, \bf 35dB, \bf 45dB, 55dB, 65dB) with properties: String: {'\bf Noise Free' '\bf 35dB' '\bf 45dB' '55dB' '65dB'} Location: 'northeast' Orientation: 'vertical' FontSize: 9 Position: [0.5254 0.6128 0.3500 0.2727] Units: 'normalized' Show all properties
h.Location = 'southoutside';
h.NumColumns = 3;
  3 件のコメント
Chunru
Chunru 2022 年 7 月 4 日
Matlab2016b may not have the NumColumns property.
When you specify the Position property too small, MATLAB may automatically adjust the size. One way to make the legend smaller is to change the font size as shown below.
Displayce the position is to find the best position for legend to avoid the overlapping with other part of the figure.
figure
openfig("fitness2snAll.fig");
h = legend
h =
Legend (\bf Noise Free, \bf 35dB, \bf 45dB, 55dB, 65dB) with properties: String: {'\bf Noise Free' '\bf 35dB' '\bf 45dB' '55dB' '65dB'} Location: 'northeast' Orientation: 'vertical' FontSize: 9 Position: [0.5254 0.6128 0.3500 0.2727] Units: 'normalized' Show all properties
h.FontSize = 5; % adjust this to meet your need
pos = h.Position;
pos(1:2) = [0.45 0.35]; % displacement
pos(3:4) = pos(3:4) % size (if too small, matlab will adjust it)
pos = 1×4
0.4500 0.3500 0.2567 0.1717
h.Position = pos
h =
Legend (\bf Noise Free, \bf 35dB, \bf 45dB, 55dB, 65dB) with properties: String: {'\bf Noise Free' '\bf 35dB' '\bf 45dB' '55dB' '65dB'} Location: 'none' Orientation: 'vertical' FontSize: 5 Position: [0.4500 0.3500 0.2567 0.1717] Units: 'normalized' Show all properties
Sadiq Akbar
Sadiq Akbar 2022 年 7 月 4 日
Thank you very much for your help.

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

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