1

I noticed that sometimes, when I plot the bars using the functions bar() or hist(), the bars plotted have no border. They are a little bit less nice to see, and I would prefer the border or a little bit of space between them. The figure shows what I got now, plotting three different datasets. The third graph is zoomed in order to show the lack of space between bars. enter image description here

I get there this has something to do with the 'histc' parameters in bar function. Without the histc parameters the bars have some space between each others, but then the bar will be centered on the edges values, whereas I want the edges values to be, well, EDGES of each bar.

This is (the relevant part of) the code I used:

 [...]
 if edges==0
        %these following lines are used to take the min and max of the three dataset
        maxx=max(cellfun(@max, reshape(data,1,size(data,1)*size(data,2))));
        minn=min(cellfun(@min, reshape(data,1,size(data,1)*size(data,2))));
        edges=minn:binW:maxx+binW;
    end
    [...]
     y{k}=histc(data{r,c}, edges);
    bar(edges,y{k} , 'histc');
    [...]
4

2 回答 2

1

我认为,如果您更改条形图的颜色,您会发现实际上有一个边框,但它并没有很好地显示出来。您还可以更改条的宽度,使它们更加清晰。

% something to plot
data = 100*rand(1000,1);
edges = 1:100;

hData = histc(data,edges);

figure
subplot(2,1,1)
h1 = bar(edges,hData,'histc');
% change colors
set(h1,'FaceColor','m')
set(h1,'EdgeColor','b')

% Change width
subplot(2,1,2)
h1 = bar(edges,hData,0.4,'histc');

在此处输入图像描述

于 2013-08-29T19:24:16.920 回答
0

Barseries对象的EdgeColorLineWidth属性控制条形轮廓。尝试使用代码并使用红色、绿色、蓝色和宽度值来获得更好的结果。

    red = 1;
    green = 1;
    blue = 1;
    width = 3;
    h = bar(edges,y{k} , 'histc');
    set(h,'EdgeColor',[red green blue],'LineWidth',width);
于 2013-08-29T23:39:41.167 回答