对文本图注释使用不同的颜色
Using different colors for text plot annotations
我有一个只有几个像素的图像图,我想在每个像素处用一个值进行注释。由于颜色在整个常规颜色图中各不相同,我无法真正为所有注释设置固定颜色,但想改变颜色。
x=1:3;
y=1:3;
m(y, x) = x .* y' * 6;
image(m);
xi = repmat(x, 3, 1);
yi = repmat(y', 1, 3);
text(xi, yi, "label");
我当然可以使用
设置颜色
text(xi, yi, "label", "color", "white");
我尝试了 3D 矩阵而不是 "white"
clabels = zeros(3, 3, 3);
clabels(:, :, 2) = 0.75; % for medium green, RGB = [0 192 0];
和一个单元格矩阵
clabels = {};
clabels(y, x) = [0 0.75 0];
在这两种情况下,使用 text(xi, yi, "label", color, clabels)
都得到了
error: invalid value for color property "color"
有没有办法为颜色 属性 创建类似矩阵的值?或者我是否必须为我想要注释的每种颜色创建一个 text
?
您可以使用 {'Property'}, {values}
格式一次指定所有文本对象的颜色。不幸的是,您不能直接在构造函数中执行此操作,但您可以使用 set
.
对 text
返回的文本对象数组执行操作
t = text(xi, yi, 'label');
% Create a cell array where each cell is a different RGB color
colors = arrayfun(@(x)rand(1,3), t, 'UniformOutput', false);
set(t, {'Color'}, colors)
我有一个只有几个像素的图像图,我想在每个像素处用一个值进行注释。由于颜色在整个常规颜色图中各不相同,我无法真正为所有注释设置固定颜色,但想改变颜色。
x=1:3;
y=1:3;
m(y, x) = x .* y' * 6;
image(m);
xi = repmat(x, 3, 1);
yi = repmat(y', 1, 3);
text(xi, yi, "label");
我当然可以使用
设置颜色text(xi, yi, "label", "color", "white");
我尝试了 3D 矩阵而不是 "white"
clabels = zeros(3, 3, 3);
clabels(:, :, 2) = 0.75; % for medium green, RGB = [0 192 0];
和一个单元格矩阵
clabels = {};
clabels(y, x) = [0 0.75 0];
在这两种情况下,使用 text(xi, yi, "label", color, clabels)
都得到了
error: invalid value for color property "color"
有没有办法为颜色 属性 创建类似矩阵的值?或者我是否必须为我想要注释的每种颜色创建一个 text
?
您可以使用 {'Property'}, {values}
格式一次指定所有文本对象的颜色。不幸的是,您不能直接在构造函数中执行此操作,但您可以使用 set
.
text
返回的文本对象数组执行操作
t = text(xi, yi, 'label');
% Create a cell array where each cell is a different RGB color
colors = arrayfun(@(x)rand(1,3), t, 'UniformOutput', false);
set(t, {'Color'}, colors)