简体   繁体   English

在matlab中绘制不同颜色的同一图中的多个直方图

[英]ploting multiple histogram in same figure with different color in matlab

i have a 600x24 matrix a, i want to make histogram of each column in same figure but with differnet color in MATLAB, i used the following code but it did not give me rainbow color,i used the following code, please help 我有一个600x24矩阵a,我想在同一图中制作每列的直方图,但在MATLAB中使用不同的颜色,我使用下面的代码,但它没有给我彩虹色,我使用下面的代码,请帮助

col = hsv(24);

hold on;

for m = 1:24
hist(a(:,m), 50);
h = findobj(gca,'Type','patch');
set(h,'FaceColor', col(m,:),'EdgeColor',col(m,:));
alpha(0.3);
end

hold off;

The MATLAB hist() function works on matrices, and processes each column of the matrix separately. MATLAB hist()函数适用于矩阵,并分别处理矩阵的每一列。 The bar() function can be used to plot the histogram yourself, and color the entries appropriately. bar()函数可用于自己绘制直方图,并适当地为条目着色。 Therefore you should be able to achieve the result using 因此,您应该能够使用获得的结果

[h,x] = hist(a,50); % histogram of every column and the bins vector
bar(x,h);           % plot histograms

% create a legend
l = cell(1,24);
for n=1:24, l{n} = num2str(n), end;
legend(l);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM