split legend into 2 rows and 3 columns

31 ビュー (過去 30 日間)
RAJAT GANGADHARAN
RAJAT GANGADHARAN 2020 年 3 月 6 日
コメント済み: RAJAT GANGADHARAN 2020 年 3 月 6 日
I have 6 legend items and I want to split the legend as 2*3. I am using Matlab 2016a

採用された回答

Ameer Hamza
Ameer Hamza 2020 年 3 月 6 日
On newer versions of MATLAB, you can set the NumColumns property of legends to get a 2x3 legend. However, in older versions, you can get two legends by adding a hidden axes. For example, the following code shows one of the ways.
ax = axes();
hold(ax);
ax2 = axes('Visible', 'off');
hold(ax2);
x = 1:10;
y = 1:10;
plot(ax, x,y, x,y+1, x,y+2);
plot(ax2, x,y+3, x,y+4, x,y+5);
% adjust the axis of hidden and visible axes to have same limits
ax.YLim(1) = min(ax.YLim(1), ax2.YLim(1));
ax2.YLim(1) = min(ax.YLim(1), ax2.YLim(1));
ax.YLim(2) = max(ax.YLim(2), ax2.YLim(2));
ax2.YLim(2) = max(ax.YLim(2), ax2.YLim(2));
legend(ax, {'plot1', 'plot2', 'plot3'}, 'Position', [0.15 0.80 0.10 0.01]);
legend(ax2, {'plot4', 'plot5', 'plot6'}, 'Position', [0.30 0.80 0.10 0.01]);
  1 件のコメント
RAJAT GANGADHARAN
RAJAT GANGADHARAN 2020 年 3 月 6 日
Thank you.

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

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