为contourf定制的色彩映射表

时间:2015-06-11 11:48:46

标签: matlab colormap contourf

我有一个3D功能,想要在[0.683 0.9545 0.9973]显示轮廓。我希望区域0 - > 0.683用红色填充,0.683 - > 0.9545为蓝色,0.9545 - > {{ 1}}为绿色,0.9973 - > 0.9973为白色。

所以基本上我有以下内容:

1.0

并尝试了

contours = [0.0 0.683 0.9545 0.9973 1.0]
contourf(x,y,z,contours)

但这不对。请问,为了得到我想要的颜色,我的色彩图应该是什么样的?

1 个答案:

答案 0 :(得分:1)

猜测一下,我会说你需要每个颜色的行数与每个范围的大小成比例。因此0.683 - > 0.6830.9545 - > 0大很多。在您的颜色贴图中,您每个只提供一行,因此Matlab假定这些颜色应在整个范围内均匀分配(即1 - > 0),其中4种颜色表示红色代表0.25 - > 0.25,蓝色适用于0.5 - > linspace等...

尝试使用以下答案:How to create a custom colormap programmatically?,但不要使用repmat,而是使用red = repmat([1 0 0], 6830, 1); blue = repmat([0 0 1], 9545 - 6830, 1); green = repmat([0 1 0], 9973 - 9545, 1); white = repmat([1 1 1], 10000 - 9973 , 1); map = [red;blue;green;white]; colormap(map); 。您需要有足够的行来计算您的4位小数精度(您可能需要重新考虑),因此您总共有 10 000 行:

map = zeros(10000,3);
map(1:6830,1) = 1;
map(6831:9545,3) = 1;
map(9546:9973,2) = 1;
map(9974:end,:) = 1;

或者:

String line;
PrintStream out = new PrintStream(outputFile);
BufferedReader br = new BufferedReader(new FileReader(outputFile));
while((line=br.readLine())!=null){
   if (!line.trim().isEmpty()){
      line+="\n";
    }
   //System.out.println(line);       
} 
相关问题