How to increase bar width without overlapping in a MATLAB bar graph?

How can you increase the width of the bars in a bar graph in MATLAB without causing the bars to overlap? The script below increases the bar width but the bars overlap:

graph = [ 1 2 ; 3 4 ; 5 6 ; 7 8 ];
bar(graph,'BarWidth',2);

Answers


The only way I know to do this is via multiple calls to bar.

function h=BarSpecial(data, overallWidth )
    colour = {'r','b'};
    [r,c] = size(data);
    h = zeros(c,1);
    width = overallWidth / c;
    offset = [-width/2 width/2];
    for i=1:c
        h(i) = bar(data(:,i),'FaceColor',colour{i},'BarWidth',width);   
        set(h(i),'XData',get(h(i),'XData')+offset(i));
        hold on               
    end    
end

The following will generate a bar chart with the bars occupying 90% of the total space.

BarSpecial(graph,0.9)

The function BarSpecial as written is not general purpose but could be extended to handle a wider range of input data.


Default width is = 0.8. If width is 1, the bars within a group touch one another. Values > 1 produce overlapping bars.

set width less than 1. e.g.

figure; bar(graph,0.4);

Need Your Help

Multiple parameters in seed lambda expression

c# entity-framework ef-code-first

I am utilizing the Seed() method to populate my database. I am trying to pre-populate one table with data based on two keys, not just one.

.net mvc and manos what's different?

asp.net ajax web-applications manos

i have interest in asp.net web app use html5 websocket, long polling.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.