有時候須要在matlab scatter繪圖中顯示不一樣顏色區分,以下圖是人體血壓高壓、低壓與年齡關係的散點圖。code
紅色點表示高壓
綠色點表示低壓blog
用 matlab 如何實現呢?
1.建立一維矩陣x,y1,y2 分別表示年齡、高壓和低壓it
x=[75;78;51;82;77;88;41;78;78;61;71;74;62;81;75;64;80;72;51;80;56;73] y1=[208;146;168;149;208;102;130;155;163;154;145;147;143;161;145;120;153;158;123;163;177;148] y2=[111;80;115;74;85;71;77;89;90;90;90;77;86;90;74;78;98;87;81;76;94;99]
2.調用scatter方法table
%繪製高壓散點圖,紅色填充 >> scatter(x,y1,'r','field') %保有已繪製圖形 >> hold on %繪製低壓散點圖,綠色填充 >> scatter(x,y2,'b','field')
或者使用半角逗號鏈接多個方法class
>> scatter(x,y1,'r','field'),scatter(x,y2,'b','field')
3.scatter用法:方法
scatter(x,y)
scatter(x,y,sz)
scatter(x,y,sz,c)
scatter(x,y,sz,c,type)
im
x: x軸座標數據
y: y軸座標數據
sz: 圖中標記大小,默認大小爲36
c: 標記顏色數據
長名稱 | 短名稱 | RGB 三元數 |
---|---|---|
'yellow' |
'y' |
[1 1 0] |
'magenta' |
'm' |
[1 0 1] |
'cyan' |
'c' |
[0 1 1] |
'red' |
'r' |
[1 0 0] |
'green' |
'g' |
[0 1 0] |
'blue' |
'b' |
[0 0 1] |
'white' |
'w' |
[1 1 1] |
'black' |
'k' |
[0 0 0] |
type: 標記形狀img
值 | 說明 |
---|---|
'o' |
圓圈 |
'+' |
加號 |
'*' |
星號 |
'.' |
點 |
'x' |
叉號 |
'square' 或 's' |
方形 |
'diamond' 或 'd' |
菱形 |
'^' |
上三角 |
'v' |
下三角 |
'>' |
右三角 |
'<' |
左三角 |
'pentagram' 或 'p' |
五角星(五角形) |
'hexagram' 或 'h' |
六角星(六角形) |
'none' |
無標記 |