histogram bins with different colors
73 次查看(过去 30 天)
显示 更早的评论
Hello Everybody,
I'd be glad if you could help me in building a histogram with different color for each histogram bin.
Before asking, I've tried to define for loops and a matrix of colors, without succeding.
My problem is that T.ConstructionYear is a 1531 x 1 numeric vector, and I'd have a different color for each bin. I left auto mode for the number of bins choice.
I've also tried to write the function for just two bins.
Thanks in advance for the help.
h1 = histogram(T.ConstructionYear, 'FaceColor', 'b');
xlabel('ConstructionYear');
ylabel('Number of Bridges');
title('Distribution of Construction Year Data');
0 个评论
采纳的回答
Scott MacKenzie
2021-4-26
编辑:Scott MacKenzie
2021-4-26
I'm not sure if you can do this with histogram. Here's what I put together using histcounts and bar instead:
d1 = rand(1531,1); % put your T.ConstructionYear data here
myColor = rand(10,3); % 10 bins/colors with random r,g,b for each
d2 = histcounts(d1);
b = bar(d2, 'facecolor', 'flat');
b.CData = myColor;
xlabel('ConstructionYear');
ylabel('Number of Bridges');
title('Distribution of Construction Year Data');
5 个评论
Scott MacKenzie
2021-5-18
Yup. Still getting threads here. Nice work. Congratulations. Arch masonry bridges rule! :)
You've got a lot going on in that chart. Are you using "full screen"? You can do this using
f = gcf;
f.WindowState = 'maximize'; % full screen
You can also play with the size of the tick label fonts using the axis FontSize property. Good luck.
更多回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Distribution Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!