MATLAB: Change bar graph color by sign

bar graphcolor coding

I have a 502×2 column matrix made up of B = [datenum, data]. There are positive nad negative data values, and I want to make all of the positive values red and all of the negative values blue, similar to the figure midway down this page: https://niwa.co.nz/climate/information-and-resources/southern-annular-mode
My code so far is just:
bar(B(:,1), B(:,2))
Is there a straightforward way to do this?
Thank you!

Best Answer

bar(B(B(:,2)>=0,1), B(B(:,2)>=0,2),'FaceColor','b')
hold on
bar(B(B(:,2)<0,1), B(B(:,2)<0,2),'FaceColor','r')