Hello Community,
I have a presentation problem regarding a plot legend that I hope you can help with. This situation is that I plot a bar chart and need to identify a single bar with a different colour when the data hits certain conditions, coded as:
figure(1)
hold on
cm = [0.90 0.90 0.90; 0 0 0];
for i = 1:length(pltvar1srt)
h=bar(i,pltvar1srt(i));
if pltvar1srt(i) == 1.71 && 4
set(h,'FaceColor',cm(1,:));
else
set(h,'FaceColor',cm(2,:));
end
end
hold off
and this produces the plot I need:
The problem is when I add the legend, due to the way I have coloured the bar, I get many data entries:
Using the legend help, I have tried to write the legend using a variety of calls - all of which haven't worked unfortunately:
legend ([data1 data10]);
legend ([data data10]);
legend ([pltvar1srt.9 pltvar1srt.10]);
legend ([pltvar1srt(9) pltvar1srt(10)]);
legend ([cm(1,:) cm(2,:)], 'Data 1', 'Data 2');
but still no luck. I have also looked at this useful function - but again, couldn't get it to work in the way I needed. I simply want the legend to have the two entries ie 'Black Data' and 'Grey Data' and be coloured appropriately.
Can anyone offer any help please?
Many thanks,
10B.