如何更改条形图中条形的颜色?

the*_*ist 2 matlab plot graph colors histogram

我想创建一个条形图,我可以在其中更改某些条形图的颜色.我的条形图的代码如下:

 y = [0.04552309, -0.001730885, 0.023943445, 0.065564478, 0.032253892, 0.013442562, ...
      -0.011172323, 0.024595622, -0.100614203, -0.001444697, 0.019383706, 0.890249809];
 bar(y)
Run Code Online (Sandbox Code Playgroud)

我希望前六个条形为黑色,最后六个条形为蓝色,但我不知道如何做到这一点.

Lui*_*ndo 6

您需要单独绘制它们(但在相同的轴上):

bar(1:6,y(1:6),'k')
hold on
bar(7:numel(y),y(7:end),'b')
set(gca,'xtick',1:numel(y))
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述