我有以下代码:
%initialize variables
titles = {'1a', '1b', '2a', '2b', '3a', '3b', '4a', '4b', '5a', '5b', '6a', '6b', '7a', '7b', '8a', '8b', '9a', '9b', '10a', '10b', '11a', '11b', '12a', '12b', '13a', '13b', '14a'};
antibodies = {'Rel-A','p-Rel-A','IkBa','p-IkBa','A20'};
x_axis = {'PBS','GOX','TNF','L','M','H'};
colours = {'r','g','b','m','c'};
Y_axis = 'Fold TNF (OD)';
%plot graphs
h = figure('name','Cytoplasm,Averaged,1h');
for i=1:5,
subplot(5,1,i)
barwitherr(std_error{2}(i,1:6),averaged_data{2}(i,1:6),'BarWidth',0.7) %note that barwitherr is a downloadable function
set(get(gca,'YLabel'), 'String', Y_axis)
set(gca, 'XTick', 1:6, 'XTickLabel', x_axis,'fontsize',18);
title(antibodies(i))
end
h=subplot(5,1,1);
set(h,'ylim',[0,15]);
h=subplot(5,1,3);
set(h,'ylim',[0,4]);
h=subplot(5,1,4);
set(h,'ylim',[0,4]);
h=subplot(5,1,5);
set(h,'ylim',[0,4]);
这很好地生成了我的图形,除了我想要更改各个子图的各个条的颜色。即如何更改第一个子画绿色的第一个栏,但其余的是蓝色?
干杯
答案 0 :(得分:1)
我认为解决方案是使用
[nelements , centers] = hist(Ydata,XData);
获取您感兴趣的数据的bin计数,然后对数据应用一些阈值,以便只有低于阈值的数据为绿色,其余为蓝色。
例如:
CentersBelowTreshold = centers(centers < MinCutoffValue);
ElementsBelowTreshold = nelements(centers < MinCutoffValue);
CentersAboveTreshold = centers(centers > MinCutoffValue);
ElementsAboveTreshold = centers(centers > MinCutoffValue;
然后绘制条形图。我想你可以修改barwitherr的源代码,因为它基本上用一个额外的输入参数绘制条形。
bar(CentersBelowTreshold,ElementsBelowTreshold,'g')
hold on
bar(CentersAboveTreshold,ElementsAboveTreshold,'b')
hold off.
答案 1 :(得分:1)
如果我理解正确,请使用this function。
如果是,那么你可以修改barwitherr.m的代码来改变颜色。
要在第114行写入后将条形颜色更改为绿色
set(handles.bar,'FaceColor','g')
将刻度线的颜色更改为红色
% replace line 126 with
h = errorbar(mean(x,1), values(xOrder,col), lowerErrors(xOrder,col), upperErrors(xOrder, col), '.r');
hc = get(h, 'Children');
set(hc(2),'color','r')
hErrorbar(col) = h;
% after line 131 include
set(hErrorbar,'color','y')
hc = get(hErrorbar, 'Children');
set(hc(2),'color','r')
希望它有所帮助。