How to set position of legend plot where outside axes??
686 ビュー (過去 30 日間)
表示 古いコメント
Hi all,
I create sample code for set legend position.
f = figure;
p = uipanel('Title','Panel','FontSize',12,...
'BackgroundColor','white',...
'Position',[.1 .1 .67 .8]);
% Construct a figure with subplots and data
subplot(2,1,1, 'Parent', p);
line1 = histogram(rand(1,1000));
title('Axes 1');
subplot(2,1,2, 'Parent', p);
line2 = histogram(rand(1,1000));
title('Axes 2');
% Construct a Legend with the data from the sub-plots
hL = legend([line1,line2],{'Data Axes 1','Data Axes 2'});
%set(hL,'location', 'bestoutside');
Here is result:

But, I want to move legend to outside of axes such as:

Do anyone know? Please help me.
Thank you so much
0 件のコメント
回答 (1 件)
Jonas
2022 年 9 月 16 日
add a Name-Value pair to your legend command, e.g.
legend('Location','eastoutside')
参考
カテゴリ
Find more on Legend in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!