How to change bars colour in MATLAB

后端 未结 3 431
生来不讨喜
生来不讨喜 2021-01-25 20:27

I am new to programming so I am learning introductory to MATLAB I was wondering how you could change colours of bar in MATLAB.

this is my script. Can someone please help

3条回答
  •  独厮守ぢ
    2021-01-25 21:00

    To use two different colors depending on y: compute a logical index depending on y values and call bar twice with appropriate arguments:

    x = [1:8];
    y = [20 30 40 50 60 70 80];
    ind = y < 40; %// logical index
    bar(x(ind), y(ind), 'facecolor', 'b', 'edgecolor', 'k') %// blue bars, black edge
    hold on %// keep plot
    bar(x(~ind), y(~ind), 'facecolor', 'g', 'edgecolor', 'k') %// green bars, black edge
    set(gca,'xtick',x)
    

    enter image description here

提交回复
热议问题