Create a stand-alone legend for tabulated data
Show older comments
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.
Accepted Answer
More Answers (0)
Categories
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!