1

我想创建一个结合了条形图和折线图的图形,为此我有以下内容:

[AX,H1,H2] = plotyy(AG_sea_ice(:,6), AG_sea_ice(:,4), TG_FP1(:,5), TG_FP1(:,4), @bar, @line);
set(H1,'FaceColor', [0.6 0.6 0.6], 'EdgeColor', [0.6 0.6 0.6]);
set(H2,'LineStyle',':', 'Color', 'r', 'marker', '+');

我还想根据 y 值对条形图中的条形进行颜色编码(而不是像上面那样将所有条形都涂成灰色),根据以前的帖子,我有以下内容:

mydata = AG_sea_ice (:,4);
    bar_h = bar(mydata);
    bar_child=get(bar_h,'Children');
set(bar_child, 'EdgeColor', 'none');
    set(bar_child,'CData', mydata);
set(bar_child,'CDataMapping', 'direct');
    mycolor=[0 0 0; 0.5 0.5 0.5; 1 1 1];

for iCount=1:length(mydata)
    if (mydata(iCount)<5)
    index(iCount)=1;
    elseif(mydata(iCount)>=10)
    index(iCount)=3;
    else
    index(iCount)=2;
    end
    end

set(bar_child, 'CData',index);
colormap(mycolor);

我的问题是如何将两者结合起来,以便条形颜色编码适用于 plotyy 图中axis1 上的条形图。另外,如果有更简单的方法来解决这个问题,请告诉我。任何帮助将非常感激。

4

0 回答 0