![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/174254/image.jpeg)
changing the histogram color
48 次查看(过去 30 天)
显示 更早的评论
Is there any way to change the color of a histogram?
0 个评论
采纳的回答
Image Analyst
2014-1-22
If you want each bar in a different color, then try the attached demo (below in blue text).
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/174254/image.jpeg)
更多回答(1 个)
Bjorn Gustavsson
2014-1-22
Yes.
help hist
There you'll see that hist with no output parameters plot the histogram with BAR, and that you can get the count and bin position out of hist: [N,X] = hist(...
help bar
There you'll find more information about how to control and set the parameters of a bar plot.
So after reading that, and messing about with get(Bh) you'll end up with this:
[N,X] = hist(...
Bh = bar(X,N,'facecolor',[0.3 0.7 0.2]);
HTH
3 个评论
Image Analyst
2014-1-22
That's why I prefer explicit, descriptive variable names. N is the pixel counts, and X is the gray level. You might write this as
axes(handles.axesImage); % Use the image axes to show the image.
imshow(grayImage);
axes(handles.axesPlot); % Use the plot axes for the plot.
[pixelCounts, grayLevels] = imhist(grayImage, 256);
bar(grayLevels, pixelCounts, 'FaceColor', [0.3 0.7 0.2]);
This will give 256 bars with each bar the color [0.3 0.7 0.2] which is greenish.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Histograms 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!