我在图中有几个补丁(请参阅下面的最小工作示例)。目前,这些补丁具有由 FaceVertexCData
确定的面颜色(引用当前颜色条的标量)和由 EdgeColor
(RGB 向量)确定的边缘颜色。我想要做的是删除面部颜色并使边缘的颜色与其各自补丁的原始面部颜色相同。
使用FaceAlpha
属性删除面部颜色很简单,但我似乎不知道如何将FaceVertexCData
属性转换为其等效的RGB代码,以便我可以将其分配给EdgeColor
。
h.fig = figure;
h.patch(1) = patch([0 1 1 0],[0 0 .3 .3],10);
h.patch(2) = patch([0 1 1 0],[.5 .5 .9 .9],5);
set(h.patch, 'FaceAlpha', 0);
最佳答案
首先获取当前颜色图和颜色条
currentCmap = colormap; % get the current colormap
theColorbar = colorbar; % get the current colorbar
然后在颜色栏中找到 cdata 值(可能有更好的方法)。
colorVertexList = linspace(theColorbar.Limits(1), theColorbar.Limits(2), size(currentCmap, 1));
为了在上面的列表中查找色 block 颜色的索引,我只使用最小的差异,如下所示
[~, patch1ColorIndex] = min(abs(h.patch(1).FaceVertexCData-colorVertexList));
[~, patch2ColorIndex] = min(abs(h.patch(2).FaceVertexCData-colorVertexList));
然后你可以从颜色图中获取rgb值
patch1Color = currentCmap(patch1ColorIndex, :);
patch2Color = currentCmap(patch2ColorIndex, :);
并设置颜色
set(h.patch, 'FaceAlpha', 0);
set(h.patch(1), 'EdgeColor', patch1Color);
set(h.patch(2), 'EdgeColor', patch2Color);
关于matlab - 如何对补丁边缘进行着色(使用颜色图)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45083855/