简体   繁体   English

八度中每个子图的单独颜色图

[英]Separate colormap for each subplot in Octave

Matlab provides an ability to set individual colormaps for each subplot. Matlab提供了为每个子图设置单独的颜色图的功能。 The same functionality described by Octave docs 八度文档描述的相同功能

Namely following phrases: 即以下短语:

Function File: cmap = colormap (hax, …) If the first argument hax is an axes handle, then the colormap for the parent figure of hax is queried or set. 函数文件:cmap = colormap(hax,…)如果第一个参数hax是轴手柄,则查询或设置hax父图形的颜色图。

But when I try to run following code, I end up having single colormap for all subplots for some reason. 但是,当我尝试运行以下代码时,由于某种原因,最终所有子图都只有一个颜色图。

clear -all;
clc;

img = zeros(128, 128);
img(64,64) = 0.2;
rad = radon(img);

x = 1;
y = 4;


s1 = subplot(y,x,1); imagesc(img);
colormap(s1, gray);
s2 = subplot(y,x,2); imagesc(rad);
colormap(s2, hot);
colorbar;

line_img = zeros(128, 128);
line_img(64, 32:64) = 0.5;
line_img(63, 32:64) = 0.4;
line_img(63, 32:64) = 0.2;
line_rad = radon(line_img);
s3 = subplot(y,x,3); imshow(line_img);
colormap(s3, gray);
s4 = subplot(y,x,4); imagesc(line_rad);
colormap(s4, hot);

colorbar;

Any help is appreciated. 任何帮助表示赞赏。 I expect to have source images in grayscale and radon transform images in "hot". 我希望源图像为灰度,而ra变换图像为“热”。 For some reason I'm getting first subplot somewhat like grayscale (it's actually not, since I initialize point with value 0.2 and octave gives me pure white color for it, while I'm expecting reasonably dark gray), and thee remaining images seem to have "hot" colormap being set. 由于某种原因,我得到的第一个子图有点像灰度级(实际上不是,因为我用0.2初始化点,并且倍频程为它提供了纯白色,而我期望是相当深的灰色),而其余图像似乎设置了“热”色图。

If you read that line from the documentation a little close you will see that is that that if you pass an axes handle that the parent figure's colormap is changed. 如果您从文档中稍稍读了这一行,您会发现,如果传递轴手柄,则会更改父图形的颜色 This is not the same as each axes having a different colormap since they're all in the same figure. 这与每个轴都具有不同颜色图的轴不同,因为它们都在同一图中。

Function File: cmap = colormap (hax, …) If the first argument hax is an axes handle, then the colormap for the parent figure of hax is queried or set . 函数文件: cmap = colormap (hax, …)如果第一个参数hax是轴手柄, 则查询或设置hax父图的颜色图

Currently, Octave does not support this functionality which was only just recently introduced in MATLAB. 当前,Octave不支持此功能,而该功能只是最近在MATLAB中引入的。

The way around this is to convert your images to RGB images prior to displaying with imshow and then the figure's colormap is irrelevant. 解决方法是在使用imshow显示之前将图像转换为RGB图像,然后图形的颜色图无关紧要。 You can do this by first converting it to an indexed image (using gray2ind ) and then to RGB with ind2rgb . 您可以通过先转换为索引图像(用做gray2ind ),然后用为RGB ind2rgb

% To display the grayscale image
rgb = ind2rgb(gray2ind(img), gray);
imshow(rgb);

As a side note, the reason that your first grayscale image is showing up as all white is that if the input to imshow is of type double , then all values are expected to be between 0 and 1. If you want to change this behavior you can use the second input of imshow to specify that you'd like to scale the color limits to match your data 作为一个侧面说明,原因是你的第一个灰度图像显示为全白的是,如果输入imshow类型为double ,那么所有的值预计是0和1之间。如果你想改变这种行为,你可以使用imshow的第二个输入来指定您要缩放颜色限制以匹配您的数据

imshow(img, [])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM