matlab - 如何对补丁边缘进行着色(使用颜色图)?

标签 matlab plot matlab-figure colormap

我在图中有几个补丁(请参阅下面的最小工作示例)。目前,这些补丁具有由 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/

相关文章:

matlab绘图跳跃不连续

apache-spark - 如何在 Apache Spark (PySpark 1.4.1) 中可视化/绘制决策树?

python - 如何更改 Pandas 时间序列图的 x-ticks 密度?

matlab - 在 Matlab 中添加向量作为图例

matlab - 如何在MATLAB中改变图例的显示格式

image-processing - 使用 MATLAB 对图像进行边界框

matlab - 如何用 100*5 矩阵的特定范围的随机数填充矩阵的列?

excel - 将时间从excel转换为matlab

matlab - 10 折交叉验证的混淆矩阵

matlab - 在matlab中,计算一列的一部分的平均值,其中另一列满足条件