简体   繁体   English

Matlab直方图中不同范围的数据使用不同的颜色

[英]Different color for different range of data in Matlab histogram

I would like to know is there any way that I can have different color for different range in the histogram so I say I want from 0 to 0.4 is blue and 0.4 to 0.8 red and 0.8 to 1 is green? 我想知道有什么方法可以使直方图中的不同范围的颜色不同,所以我说我想从0到0.4是蓝色,从0.4到0.8是红色,从0.8到1是绿色?

I know I can change the color of histogram bins and have two histogram with two different colors and all other things with bar commands like below : 我知道我可以更改直方图容器的颜色,并使用如下所示的bar命令使用两个具有两种不同颜色的直方图和所有其他东西:

[elements,centers]=hist('data1','#of bins');
bar(centers, elements,'FaceColor','r','EdgeColor','k');
hold on
[elements2,centers2]=hist('data2','#of bins');

But how to change the color within histogram? 但是如何更改直方图中的颜色?

The way to get data with different colors is to split the data into groups. 获取具有不同颜色的数据的方法是将数据分为几组。 In your case, split the data into three groups. 根据您的情况,将数据分为三组。

For example with three groups: 例如三个组:

hist(data1);
hold on;
hist(data2);
hist(data3); 
h = findobj(gca,’Type’,’patch’);
display(h) 
set(h(1),’FaceColor’,’r’,’EdgeColor’,’k’);
set(h(2),’FaceColor’,’g’,’EdgeColor’,’k’);
set(h(3),’FaceColor’,’b’,’EdgeColor’,’k’);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM