Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用matlab绘制不同颜色的条形图_Matlab - Fatal编程技术网

用matlab绘制不同颜色的条形图

用matlab绘制不同颜色的条形图,matlab,Matlab,我根据一些值绘制了一个条形图,但我想知道我是否可以用不同的颜色绘制它。例如,如果精度小于25%,则该条变为红色;如果精度在25%和50%之间,则该条变为黄色;如果精度大于50%,则该条变为绿色。。有什么帮助吗 我的代码: x = [0.1 0.5 1 2 3]; y = [2.0407 10.2108 19.8171 36.6688 52.2866]; xplot = 1:numel(x); figure; bar(xplot,y); ylabel('Accurac

我根据一些值绘制了一个条形图,但我想知道我是否可以用不同的颜色绘制它。例如,如果精度小于25%,则该条变为红色;如果精度在25%和50%之间,则该条变为黄色;如果精度大于50%,则该条变为绿色。。有什么帮助吗

我的代码:

 x = [0.1 0.5 1 2 3];
 y = [2.0407   10.2108   19.8171   36.6688   52.2866];
 xplot = 1:numel(x); 
 figure;
 bar(xplot,y);
 ylabel('Accuracy');
 xlabel('level');
 set(gca,'XTick', xplot); 
 set(gca,'XTickLabel', x);
 ylim([0 100]);
我的回答是:

x=[0.10.5123];
y=[2.040710.210819.817136.668852.2866];
xplot=1:numel(x);
fHand=数字;
A轴=轴(“父轴”,FH轴);
保持(和“开”)
对于i=xplot
如果x(i)<0.25
条(i,y(i),‘父’,a和‘脸颜色’,‘红色’)
elseif x(i)0.5
条(i,y(i),‘父’,a和‘面颜色’,‘绿色’)
结束
结束
集合(gca,'XTick',xplot);
集合(gca,'XTickLabel',x);
ylabel(“准确度”);
xlabel(“级别”);
ylim([01100]);
这让你:

非常感谢,它工作得非常完美,我们可以将Y轴仅更改为3个值:VeryBad(小于25%)、bad(25%和50%)和Good(超过50%),而不考虑确切的百分比吗?@SMH,这是一个不同的问题(答案是,看看
set(gca,'YTick',…)
set(gca,'yticklab',…)
。如果答案对你有帮助,你应该投赞成票和/或接受它。
x = [0.1 0.5 1 2 3];
y = [2.0407   10.2108   19.8171   36.6688   52.2866];
xplot = 1:numel(x); 

fHand = figure;
aHand = axes('parent', fHand);
hold(aHand, 'on')

for i=xplot
    if x(i) < 0.25
        bar(i, y(i), 'parent', aHand, 'facecolor', 'red')
    elseif x(i) <= 0.5
        bar(i, y(i), 'parent', aHand, 'facecolor', 'yellow')
    elseif x(i) > 0.5
        bar(i, y(i), 'parent', aHand, 'facecolor', 'green')
    end
end

set(gca,'XTick', xplot); 
set(gca,'XTickLabel', x);

ylabel('Accuracy');
xlabel('level');

ylim([0 100]);