Create a stand-alone legend for tabulated data
显示 更早的评论
I'm analyizing old datasets for work. As part of this work I am grouping the data into bins as shown in the table. I am then creating PDF reports of the data, and as part of that pdf creation I need a stand alone legend to insert into its own area. Historically I had done a continuous color scale, and was easily able to produce a stand alone colorbar, but the powers who be would like discrete data groupings.
I am struggling with producing figure handles in a loop that then can be used to produce a stand alone legend. All attempts are failing. The general code is this (I've stripped all my attempts out of the the legend producer):
dat_bins=readtable("Bin_Input.xlsx");
%create RGB's for dat_bins
for j=1:length(dat_bins.bin_color)
if matches(string(dat_bins.bin_color(j)),"b")
dat_bins.rgb{j}=[0 0 1];
elseif matches(string(dat_bins.bin_color(j)),"g")
dat_bins.rgb{j}=[0 1 0];
elseif matches(string(dat_bins.bin_color(j)),"y")
dat_bins.rgb{j}=[1 1 0];
elseif matches(string(dat_bins.bin_color(j)),"o")
dat_bins.rgb{j}=[1 165/255 0];
else
dat_bins.rgb{j}=[1 0 0];
end
end
fig_leg=figure('Visible', 'on'); %create stand alone legend
axis off
for k=1:length(dat_bins.bin_start)
fig_leg(k) = plot(nan, nan, 'color', dat_bins.rgb{k});
end
legend(fig_leg, {string(dat_bins.bin_name)'})
Any help would be greatly appreciated.
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Legend 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!