Adding legend to reference line in a plot

1 次查看(过去 30 天)
Hi,
As you can see below, I am plotting bar graphs. There is additionally also a red reference line in the plot. Now I want to add a legend, however not as the default for the bar plots, but for the reference line. How can I do that? Additionally, how can I have the reference line going over the entire range of the x axis in this specific case? Many thanks and here the code:
model_series = [65,50,0; 0,0,60];
model_error = [0, 0,0;0,0,0];
h = bar(model_series);
set(h,'BarWidth',1); % The bars will now touch each other
set(gca,'YGrid','on')
set(gca,'GridLineStyle','-')
set(gca,'YLim',[0 100])
title(['SVM Classification'])
hline = refline([0 63]);
hline.Color = 'r';
set(gca,'xtick',[1 2 3 4])
set(gca,'xticklabel',{'Condition 1','Condition 2'})
set(get(gca,'YLabel'),'String','Classification Accuracy')
hold on;
numgroups = size(model_series, 1);
numbars = size(model_series, 2);
groupwidth = min(0.8, numbars/(numbars+1.5));
for i = 1:numbars
% Based on barweb.m by Bolu Ajiboye from MATLAB File Exchange
x = (1:numgroups) - groupwidth/2 + (2*i-1) * groupwidth / (2*numbars); % Aligning error bar with individual bar
errorbar(x, model_series(:,i), model_error(:,i), 'k', 'linestyle', 'none');
end

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Legend 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by