title: Matlab bars: changing the color of the bar and the space between bars and axes
body: <p>I have a tricky question, which I think cannot be simply answered.</p>
  
  <p>I have a large data table and want to save bar charts for each 2 corresponding mean values. I already did that with "for loop", but I cannot set different colors to my bars and cannot set proper spaces between bars and axes.</p>
  
  <p>That's the simplest example:</p>
  
  <pre><code>k = [2 5]
  bar(k)
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/rhEV0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rhEV0.png" alt="Two bars on one plot"></a></p>
  
  <p>Matlab thinks about those data [2 5] as about one "group" and it does not give a possibility of changing color for only one bar.</p>
  
  <p>Of course, when we have different "groups", colors are changeable.</p>
  
  <pre><code>y = bar([1 2 3; 4 5 6]);
  y(2).FaceColor = 'red';
  </code></pre>
  
  <p>But what about my example? I need only two bars, and I need to color them differently. Also, I want to set a small space between each bar and the axes (and again with two bars it is not that simple, and I cannot use "bar width" because that doesn't give me what I really want).</p>
  
  <p>Does anyone know how to get around this?</p>
  
  <p>Thanks for any reply!
  Mary</p>