フィルターのクリア

How to remove empty space after legend?

21 ビュー (過去 30 日間)
haohaoxuexi1
haohaoxuexi1 2022 年 12 月 8 日
コメント済み: Voss 2022 年 12 月 9 日
Can anyone please give me some advice on how to remove the area below the legend.
The code is below, thanks.
C_Span = [4 8 12];
Length_C_Span = length(C_Span);
% standard plot size
x0_d=10; y0_d=10; width_d=675; height_d=width_d/(5/3); % figure default size
%height_d=675;
figure(1);
plot([1 2 3], [1 5 7]);
hold on;
plot([1 2 3], [4 5 8]);
hold on;
plot([1 2 3], [1 5 9]);
hold off;
%grid on;
box on;
for i = 1:Length_C_Span
LegendInfo{i} = ['{\it {\beta}} = ', num2str(C_Span(i))];
end
legend(LegendInfo, 'Location', 'SouthOutside', 'fontname', 'Times New Roman', 'fontsize', 12, 'NumColumns', 3);
set(gcf, 'position', [x0_d,y0_d,width_d,height_d]);

採用された回答

Voss
Voss 2022 年 12 月 9 日
編集済み: Voss 2022 年 12 月 9 日
You can adjust the axes height as below (I'm using a red figure so you can see the space beneath the axes here in the online environment):
C_Span = [4 8 12];
Length_C_Span = length(C_Span);
% standard plot size
x0_d=10; y0_d=10; width_d=675; height_d=width_d/(5/3); % figure default size
%height_d=675;
% figure(1)
figure('Color','r');
plot([1 2 3], [1 5 7]);
hold on;
plot([1 2 3], [4 5 8]);
hold on;
plot([1 2 3], [1 5 9]);
hold off;
%grid on;
box on;
for i = 1:Length_C_Span
LegendInfo{i} = ['{\it {\beta}} = ', num2str(C_Span(i))];
end
legend(LegendInfo, 'Location', 'SouthOutside', 'fontname', 'Times New Roman', 'fontsize', 12, 'NumColumns', 3);
set(gcf, 'position', [x0_d,y0_d,width_d,height_d]);
% increase axes height by 0.07 (and decrease the bottom location by same
% amount):
adjustment = 0.07; % change this to what you think looks good
ax_pos = get(gca(),'Position');
ax_pos([2 4]) = ax_pos([2 4])+[-1 1]*adjustment;
set(gca(),'Position',ax_pos)
  2 件のコメント
haohaoxuexi1
haohaoxuexi1 2022 年 12 月 9 日
編集済み: haohaoxuexi1 2022 年 12 月 9 日
Thanks,
I will try this method.
Voss
Voss 2022 年 12 月 9 日
You're welcome!

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

その他の回答 (1 件)

Arif Hoq
Arif Hoq 2022 年 12 月 9 日
編集済み: Arif Hoq 2022 年 12 月 9 日
you can change your lengend location to "northwest" or "Southeast"
legend(LegendInfo, 'Location', 'northwest', 'fontname', 'Times New Roman', 'fontsize', 12, 'NumColumns', 3);
"
  1 件のコメント
haohaoxuexi1
haohaoxuexi1 2022 年 12 月 9 日
I want it keep outside the plot. I know I can put it inside, there is even an option called "best" which will put it in a proper position inside the plot.

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

カテゴリ

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

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by