【问题标题】:Why sometimes the bars with bar or hist have no border?为什么有时带有 bar 或 hist 的条形图没有边框?
【发布时间】:2013-08-29 15:34:13
【问题描述】:

我注意到有时,当我使用函数 bar() 或 hist() 绘制条形图时,绘制的条形图没有边框。它们看起来不太好看,我更喜欢它们之间的边界或一点空间。 该图显示了我现在得到的结果,绘制了三个不同的数据集。第三张图被放大以显示条之间的空间不足。

我知道这与 bar 函数中的 'histc' 参数有关。如果没有 histc 参数,条形之间会有一些空间,但是条形将以边缘值为中心,而我希望边缘值是每个条形的边缘。

这是我使用的代码(相关部分):

 [...]
 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');
    [...]

【问题讨论】:

    标签: matlab graph plot histogram


    【解决方案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');
    

    【讨论】:

      【解决方案2】:

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

          red = 1;
          green = 1;
          blue = 1;
          width = 3;
          h = bar(edges,y{k} , 'histc');
          set(h,'EdgeColor',[red green blue],'LineWidth',width);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-12-10
        • 2021-10-30
        • 2020-03-02
        • 1970-01-01
        • 1970-01-01
        • 2022-01-13
        • 2021-10-30
        相关资源
        最近更新 更多