Assigning different colors in a single histogram

4 ビュー (過去 30 日間)
Niraj Bal Tamang
Niraj Bal Tamang 2021 年 12 月 12 日
回答済み: Kush 2023 年 7 月 8 日
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

採用された回答

Kush
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.
You can look into the facecolour property of Histogram to understand this function better.
data = rand(1000,1); %Replace your data here
binEdges = 0:0.1:1
binEdges = 1×11
0 0.1000 0.2000 0.3000 0.4000 0.5000 0.6000 0.7000 0.8000 0.9000 1.0000
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 件)

カテゴリ

Help Center および File ExchangeHistograms についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by