Assigning different colors in a single histogram
4 次查看(过去 30 天)
显示 更早的评论
I have a matrix of slope data. I generated a histogram using histogram(Slope) command. I want to assign different colors to the histogram such that 0-0.5 is blue and 0.5-1 is red with legend. Can anyone please help me how to do this? I have attached the data and a sample figure which i am trying to make here.
Thank you
0 个评论
采纳的回答
Kush
2023-7-8
You can choose to separate your data based on the threshold and then use the hold on function to display both histograms together.
data = rand(1000,1); %Replace your data here
binEdges = 0:0.1:1
hold on
data1 = data(data<0.5);
data2 = data(data>=0.5);
histogram(data1,'FaceColor','b',BinEdges=binEdges)
histogram(data2, 'FaceColor','r',BinEdges=binEdges)
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Histograms 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!