如何在八度中设置用户定义的色彩图?

时间:2018-08-13 09:09:02

标签: plot colors octave contour colormap

我有一段琐碎的代码,可以计算一些数量并将其绘制为轮廓:

%Calculate Biot number vs. h for a selected material
h = (0:5:1000)';
mat = "Copper";
lambda = 386;
r = (0:0.25:50);  %In cm
 R = r./100; %In m
%Calculate matrix of Bi values
% R = length(h) x C = length(r)
Bi = (h.*R)/lambda;
%Contour Plot of results
%Set boundaries at Bi = 0, 0.1, 1
conts = [0, 0.1, 1];
ptitle = ["Biot Number for a ", mat, " Sphere"];
%Create a personalized colormap with 30 values.
%    0<Bi<0.1  Green
%    0.1<=Bi<1 Yellow
%    Bi >= 1   Red
my_green = [229,255,204]./255;
my_yellow = [255,255,204]./255;
my_pink = [255,229,204]./255;
my_cmap = [repmat(my_green, 10, 1); repmat(my_yellow, 10, 1); repmat(my_pink, 10, 1) ];
clf;
colormap (my_cmap);
contourf(h, r, Bi, conts, 'showtext', 'on');
title(ptitle)
xlabel ("h(W/m^2*K)");
ylabel ("r(cm)");

结果缺少中间颜色(黄色):

Result with missing color

对此可以做什么?

2 个答案:

答案 0 :(得分:1)

轮廓太少,因此选择了错误的颜色。如果您进行contourf(h, r, Bi, 0:0.2:1, 'showtext', 'on');,您将得到:

More contours

此外,我建议使“绿色”和“黄色”更加不同,因为在某些显示器上可能很难区分它们。


这就是我的意思,“玩L, M, N

conts = [0, 0.1, 1];
ptitle = ["Biot Number for a ", mat, " Sphere"];
%Create a personalized colormap
my_green = [229,255,204]./255;
my_yellow = [255,255,204]./255;
my_pink = [255,229,204]./255;
my_cmap = [repmat(my_green, 10, 1); repmat(my_yellow, 90, 1); repmat(my_pink, 1, 1) ];

figure(); contourf(h, r, Bi, conts, 'showtext', 'on');

colormap (my_cmap);
caxis([0 1.01])
title(ptitle)
xlabel ("h(W/m^2*K)");
ylabel ("r(cm)");

enter image description here

顺便说一句,我在MATLAB R2018a上运行了此功能,以防您想知道为什么没有得到完全相同的东西。

答案 1 :(得分:0)

添加以下代码来定义数量并生成颜色图,该过程可以自动化。

conts = [0, 0.05, 0.1, 0.3, 0.7, 1];
%Create a personalized colormap with 50 values distributed proportionally to Bi values
step = 50/max(max(Bi));
L = ceil(step*0.1);
M = ceil(step*(1-0.1));
H = ceil(step*(max(max(Bi))-1));
my_green = [229,255,204]./255;
my_yellow = [255,255,204]./255;
my_pink = [255,229,204]./255;
my_cmap = [repmat(my_green, L, 1); repmat(my_yellow, M, 1); repmat(my_pink, H, 1)];

获取:

enter image description here