[英]Change the color of the bar of histogram in Matlab
我正在尝试打印直方图,但是我需要所有大于特定值(例如250)的橙色值。
输出为:
我需要它是这样的: 任何帮助,这是代码:
fh = figure;
hist(PZ);
saveas(fh, strcat('Figures\window), 'jpg')
close(fh);
我将数据分为两组。大于250的值和小于250的值。均为绝对值。
然后,您可以将此代码设置为不同的直方图颜色吗?
hist(data1);
hold on;
hist(data2);
h = findobj(gca,’Type’,’patch’);
display(h)
set(h(1),’FaceColor’,’b’,’EdgeColor’,’k’);
set(h(2),’FaceColor’,rgb('orange'),’EdgeColor’,’k’);
一种解决方法是使用bar
来绘制数据,但是在这种情况下,您只能使用它提供的颜色,即: 'b' | 'r' | 'g' | 'c' | 'm' | 'y' | 'k' | 'w'
'b' | 'r' | 'g' | 'c' | 'm' | 'y' | 'k' | 'w'
'b' | 'r' | 'g' | 'c' | 'm' | 'y' | 'k' | 'w'
。 这是执行此操作的示例代码:
%// Generate data
data = randn(2000,1);
bins = -5:5;
[N,X] = hist(data,bins);
%% //Color by count
LIMIT_VAL = 500;
figure();
bar(X,N,'b');hold on;
bar(X,N.*(N<LIMIT_VAL),'r'); hold off;
%% //Color by bin position
LIMIT_VAL = 2;
figure();
bar(X,N,'b');hold on;
bar(X(abs(X)>=LIMIT_VAL),N(abs(X)>=LIMIT_VAL),'r'); hold off;
另一种方法是通过修改@lakesh提到的补丁颜色。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.