【问题标题】:change color to bar plot Matlab将颜色更改为条形图 Matlab
【发布时间】:2014-11-14 01:38:22
【问题描述】:

我有矩阵 A 并制作了一个条形图

A = rand(15,9);
h = bar(A);

现在我想根据下面定义的颜色图“colorset”为每组条形(A 的每一行)着色

colorset = [0   0   1;...
1   0   0;...
0   1   0;...
0   0   0.172413793103448;...
1   0.103448275862069   0.724137931034483;...
1   0.827586206896552   0;...
0   0.344827586206897   0;...
0.517241379310345   0.517241379310345   1;...
0.620689655172414   0.310344827586207   0.275862068965517]

我尝试做类似的事情

set(get(h,'children'),'cdata', A );
colormap(colorset); 

但没有运气

【问题讨论】:

    标签: matlab plot bar-chart


    【解决方案1】:

    我认为这应该会有所帮助:

       for hi = 1:numel(h)
            set(h(hi), 'FaceColor', colorset(hi,:))
       end
    

    之前(原色):

    之后(新颜色):

    【讨论】:

      猜你喜欢
      • 2018-10-28
      • 2011-08-03
      • 2012-01-19
      • 1970-01-01
      • 2014-08-06
      • 2023-01-26
      • 2021-09-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多