plot - 如何在 Octave 中设置用户定义的颜色图?
问题描述
我有一段简单的代码可以计算一些数量并将其绘制为轮廓:
%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)");
结果缺少中间色(黄色):
关于这个还能做什么?
解决方案
您的轮廓太少,因此选择了错误的颜色。如果你这样做contourf(h, r, Bi, 0:0.2:1, 'showtext', 'on');
,你会得到:
另外,我建议让“绿色”和“黄色”更加不同,因为在某些显示器上可能难以区分它们。
这就是我所说的“玩弄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)");
顺便说一句,我在 MATLAB R2018a 上运行了这个,以防你想知道为什么你没有得到完全相同的东西。
推荐阅读
- c - 如何将结构中的一些信息打包到 2 字节缓冲区中?
- google-play-console - 如何处理短信/通话记录的谷歌控制台发布声明表
- meteor - 在通过 snap 安装的 Rocketchat 中访问流星外壳
- google-apps-script - 无法从独立脚本(Google Apps 脚本)激活工作表
- javascript - 在 Back4App 中使用 JS 按日期查询
- docker - 如何在同一台 Windows 机器上的 Windows Docker 容器上将顺序 IP 地址分配给多个托管的 .net 核心 api
- haskell - Haskell 标记“#”
- r - 混淆矩阵创建问题
- java - 如何在访问数据库中添加 currentTime?
- r - 如何完成时间序列中的缺失值