How to change color of bar graph?

Hello
This is the question I need to answer. http://i.imgur.com/ZHr4BPm.png
So far my function only reads
function eval = plotupc(x)
bar(x,'histc')
end
When I try to change the color of the graph, it stops my graph from being a histogram. Also, how can I make it so that my graph starts at 0 rather than 1

Answers (2)

hb=bar(x,'histc');
set(hb,'FaceColor','k')

3 Comments

Thanks for that. Do you know how I would be able to have my bars span 0-1 rather than 1-2 and so on and so forth? Basically just shift the graph left by 1.
hb = bar(0:7,[-1 1 1 0 1 1 -1 0],'histc');
I'm just not understanding what the 'histc' option is for. It's not listed as a valid option to bar() so I think it's just ignored. So why are you passing it in? I don't have it in my code below.

Sign in to comment.

Try this:
x = randi(10, [1,15])-5
xAxis = .5:length(x)
hb=bar(xAxis, x, 'BarWidth', 0.95);
set(hb,'FaceColor', [0.3 0.1 0.3]); % color = [R, G, B] in 0-1 range
% Now make it look nice.
fontSize = 20;
grid on;
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
title('Bar Chart', 'FontSize', fontSize);
ylabel('x', 'FontSize', fontSize);
xlabel('xAxis', 'FontSize', fontSize);

Categories

Find more on MATLAB in Help Center and File Exchange

Asked:

on 13 Mar 2013

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!