Reputation: 1316
I am trying to print a Histogram but I need all the values which is bigger than a specific value(250 for example) to be in orange.
The output is:
and I need it to be something like that :
Any Help,
This is the code:
fh = figure;
hist(PZ);
saveas(fh, strcat('Figures\window), 'jpg')
close(fh);
Upvotes: 0
Views: 3159
Reputation: 24169
One way to go about this is using bar
to plot your data, but in this case you are limited to the colors it provides, which are: 'b' | 'r' | 'g' | 'c' | 'm' | 'y' | 'k' | 'w'
. Here's a sample code to do that:
%// 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;
Another way is by modifying the patch color as was mentioned by @lakesh.
Upvotes: 1
Reputation: 29064
I would split the data into two groups.Values greater than 250 and values lesser than 250. Both in absolute values.
Then, can you this code to set the color of histogram to be different
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’);
Upvotes: 1