How do I get a "tabular" legend?
古いコメントを表示
In MatlabR2015b, I am plotting a 2D scatter plot of "Performance" that is a function of two independent variables "Active agent" & "Temp". I have 3 Active Agents and 4 Temps. In scatter plot, I am using a 12 colors, one for each (ActiveAgent,Temp) pair. I want to customize legend so that it appears in a tabular form like (C1 would be like marker 'o' in its respective colors)
Temp1 Temp2 Temp3 Temp4
Agent1 C1 C2 C3 C4
Agent2 C5 C6 C7 C8
Agent3 C9 C10 C11 C12
How can I do this?
採用された回答
その他の回答 (2 件)
Shane L
2018 年 3 月 23 日
1 投票
If you are looking for a code that is built to create a "tabular" legend, my GridLegend function on the File Exchange will create a "legend" (actually a legend-like axis) with row and column labels. My GridLegend function is not as versatile as Kelly's legendflex function, but it will give you a "tabular" legend with no additional work on the user's end.
Steven Lord
2018 年 3 月 23 日
% Generate data and set up the axes
x = linspace(0, 2*pi, 500);
axis([0 2*pi -8 8]);
hold on
% Plot 8 sine curves, naming each n*sin(n*x) for legend purposes
for n = 1:8
plot(x, n.*sin(n*x), 'DisplayName', sprintf('%d*sin(%d*x)', n, n));
end
% Turn on the legend
L = legend('show');
% Make it 2-by-4 instead of 8-by-1
L.NumColumns = 4;
This isn't exactly what the original poster asked for, but it's close.
カテゴリ
ヘルプ センター および File Exchange で Legend についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


