[英]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.