? MatLab contourf and colorbar
我試著透過下列程式片段去了解 MatLab 的兩個命令 contourf() and colorbar
contourf() 畫的是 >= 的 contour 而且會把 >= 的部分填滿顏色
colorbar 則是在圖的旁邊把等位線的值跟對應的顏色標出來 可是照我下面的
程式顯示的結果不太對勁
對照圖一的等位線群跟圖二的填滿的等位線群 紅色區域應該是 >= 1
棕色區域則是 >= 0 藍色區域則是 >= -1 而空白區域則是 < -1
可是這樣跟旁邊的色表 (colorbar) 根本對不起來 根據色表
藍色 >= -1.0 and < -0.5
綠色 >= -0.5 and < 0.0
棕色 >= 0.0 and < 0.5
紅色 >= 0.5 and < 1.0
而且這一來 >=1 的部分怎麼表示?
by Cheng Cosine
Jan/02/2k8 NC
clear all; clc;
% generate field to plot
P = peaks;
Pmin = min(P(:)); Pmax = max(P(:));
% rescale to desired range of field values
Psmin = -2.0E0; Psmax = 2.0E0;
Pscaled = Psmin+( Psmax-Psmin )*( P-Pmin )/( Pmax-Pmin );
v = [-1, 0, 1];
% ---------------------------------------------------------
% Case-000 MatLab default
figure
[cs, h] = contour(Pscaled);
colorbar
clabel(cs)
% ---------------------------------------------------------
% Case-01
cmap1 = [0.0 0.0 1.0; ...
0.0 1.0 0.0; ...
0.5 0.5 0.0; ...
1.0 0.0 0.0];
figure
colormap(cmap1)
[cs1, h1] = contourf(Pscaled, v);
colorbar
clabel(cs1, v)
--
┌─────◆KKCITY◆─────┐ KK免/費/撥/接 ◤
│ bbs.kkcity.com.tw │▏電話(1):449◤1999 電話(2):4058-6000
└──《From:152.16.233.74 》──┘▏帳號:kkcity 密碼:kkcity
--
Programming 近期熱門文章
PTT數位生活區 即時熱門文章