multiple histogram color scheme

38 ビュー (過去 30 日間)
Maggie liu
Maggie liu 2021 年 7 月 14 日
コメント済み: Star Strider 2021 年 7 月 14 日
Hi,
I'm trying to plot multiple histograms on one plot, but I would like to have the overlapped bits shown as the oringal color (currently I have faceAlpha set to 0.3, so the colors are all mixed together when they overlap).
How can I do this? thanks!
This is what I currently have
hold on
h1 = histogram(data1,Edges,...,'EdgeColor',[0 0.4470 0.7410],...
'FaceColor',[0 0.4470 0.7410],'FaceAlpha',0.3,'LineWidth',1.5);
h2 = histogram(data2,Edges,...,'EdgeColor',[0.4940 0.1840 0.5560],...
'FaceColor',[0.4940 0.1840 0.5560],'FaceAlpha',0.3,'LineWidth',1.5);
h3 = histogram(data3,Edges,...,'EdgeColor',[0.4660 0.6740 0.1880],...
'FaceColor',[0.4660 0.6740 0.1880],'FaceAlpha',0.3,'LineWidth',1.5);
  2 件のコメント
dpb
dpb 2021 年 7 月 14 日
"plot multiple histograms on one plot, but I would like to have the overlapped bits shown as the oringal color"
I don't follow precisely what you envision here -- what is "original" color defined to be--you have a specific color for each of the three histograms, which one is the "original" one?
Maggie liu
Maggie liu 2021 年 7 月 14 日
編集済み: Maggie liu 2021 年 7 月 14 日
@dpb sorry for not explaining this clearly.
What I'm thinking was, suppose for a particular bar, data 1(blue) > data 2(yellow) > data3(green). I would like the bar to look like blue on top of yellow on top of green, instead of all the colors blending together due to my face alpha setting (the reason why I've set faceAlpha=0.3 is so that data beneath can actually be visible)
I hope this diagram helps explain things...

サインインしてコメントする。

採用された回答

Star Strider
Star Strider 2021 年 7 月 14 日
編集済み: Star Strider 2021 年 7 月 14 日
Since all the edges appear to be the same, it might be easiest to get the outputs of the histogram calls, however instead using histcounts, concatenate them into one matrix, and use the bar function to plot them as grouped bars as described in Display Groups of Bars
Example —
Edges = (1:6)/10;
Ctrs = mean(diff(Edges))/2+Edges(1:end-1);
N1 = histcounts(rand(1,100),Edges);
N2 = histcounts(rand(1,100),Edges);
N3 = histcounts(rand(1,100),Edges);
Nmtx = [N1; N2; N3];
figure
bar(Ctrs, Nmtx)
xticks(Ctrs)
This of course assumes that ‘Edges’ are regularly spaced.
EDIT — (14 Jul 2021 at 20:08)
The other option of coursee is to Display Stacked Bars
figure
bar(Ctrs, Nmtx, 'stacked')
xticks(Ctrs)
.
  2 件のコメント
Maggie liu
Maggie liu 2021 年 7 月 14 日
Thank you!
Star Strider
Star Strider 2021 年 7 月 14 日
As always, my pleasure!
.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Distribution Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by