Yang-Ming University, Taipei, Taiwan Graphics II
Colormap
Color Map RGB Matrix of color map Red: 0~1 Green: 0~1 Blue: 0~1 R G B 0.5 1 RGB Red: 0~1 Green: 0~1 Blue: 0~1 Matrix of color map
Default cmaps help colormap Create a 20-level hot cmap gray jet hot 0.1429 0 0 0.2857 0 0 0.4286 0 0 0.5714 0 0 0.7143 0 0 0.8571 0 0 1.0000 0 0 1.0000 0.1429 0 1.0000 0.2857 0 1.0000 0.4286 0 1.0000 0.5714 0 1.0000 0.7143 0 1.0000 0.8571 0 1.0000 1.0000 0 1.0000 1.0000 0.1667 1.0000 1.0000 0.3333 1.0000 1.0000 0.5000 1.0000 1.0000 0.6667 1.0000 1.0000 0.8333 1.0000 1.0000 1.0000 help colormap gray jet hot hsv …… Create a 20-level hot cmap hot(20) colormap(hot(20))
User-Defined Color Map 1 0 0 0.1053 0.8947 0 0.0526 0.9474 0 0 0.1053 0.8947 0 0.0526 0.9474 0 0 1 0 0 0.1053 0 0 0.0526 0 0 0 . . . col1=[zeros(20,1),zeros(20,1),linspace(0,1,20)']; col2=[zeros(20,1),linspace(0,1,20)',linspace(1,0,20)']; col3=[linspace(0,1,20)',linspace(1,0,20)',zeros(20,1)]; cmap=[col1;col2;col3]; colormap(cmap); colorbar . . . . . .
製作一從黑到紅,紅到黃,黃到綠的colormap,更換無尾熊 的色階為此colormap (MATLAB會把執行結果顯示在command window上)
Graphics in 3-D
3-D Plot 3-D line plot Syntax plot3(X1,Y1,Z1,...,Xn,Yn,Zn) t = 0:pi/50:10*pi; st = sin(t); ct = cos(t); figure; plot3(st,ct,t) hold on plot3(ct,st,t) grid on 3-D line plot Syntax plot3(X1,Y1,Z1,...,Xn,Yn,Zn) t = 0:pi/50:10*pi; st = sin(t); ct = cos(t); figure; plot3(st,ct,t)
3-D Plot by Specifying Line Style Description - Solid line (default) -- Dashed line : Dotted line -. Dash-dot line Marker Description o Circle + Plus sign * Asterisk . Point x Cross s Square d Diamond ^ Upward-pointing triangle v Downward-pointing triangle > Right-pointing triangle < Left-pointing triangle p Pentagram h Hexagram Color Description y yellow m magenta c cyan r red g green b blue
3-D Plot – Specify Line Style Syntax plot3(X1,Y1,LineSpec1,...,Xn,Yn,LineSpecn) ('CLM': color, line, marker) t = 0:pi/50:10*pi; st = sin(t); ct = cos(t); figure; plot3(st,ct,t,'r-')
3-D Plot – Change Properties of Line plot3(...,'PropertyName',PropertyValue,...) Line properties Color LineStyle LineWidth Marker MarkderSize MarkerEdgeColor MarkerFaceColor …
3-D Plot – mesh Syntax mesh(X,Y,Z) mesh(Z) [X,Y] = meshgrid(-8:.5:8); R = sqrt(X.^2 + Y.^2) + eps; Z = sin(R)./R; figure; mesh(Z)
3-D Plot – surf Surface plot Syntax surf(X,Y,Z) surf(X,Y,Z,C) [X,Y] = meshgrid(1:0.5:10,1:20); Z = sin(X) + cos(Y); C = X.*Y; surf(X,Y,Z) colorbar surf(X,Y,Z,C) Surface plot Syntax surf(X,Y,Z) surf(X,Y,Z,C) The function plots the values in matrix Z as heights above a grid in the x-y plane defined by X and Y.
3-D Sphere Plot figure; sphere % Create a 20-by-20 faces sphere
3-D Sphere Plot [x,y,z] = sphere; figure; surf(x,y,z) hold on surf(x+3,y-2,z) % centered at (3,-2,0) surf(x,y+1,z-3) % centered at (0,1,-3) [x,y,z] = sphere; figure; mesh(x,y,z)
3-D Plot – patch Create one or more filled polygons Syntax patch(X,Y,C) patch(X,Y,Z,C) x = [2 5; 2 5; 8 8]; y = [4 0; 8 2; 4 0]; c = [0; 1]; figure; patch(x,y,c) colorbar
3-D Plot – patch figure; Pl_lat = patch('Faces', data.faces_l, 'Vertices', data.vertices_l, 'FaceColor', [0.8 0.8 0.8], 'EdgeColor', 'none', 'Facealpha', 0.5); view(gca, -90,0); light(gca, 'Style', 'infinite', 'Position', [0 1 0]) set(Pl_lat, 'FaceLighting', 'gouraud'); light(gca, 'Style', 'infinite', 'Position', [0 -1 0]) light(gca, 'Style', 'infinite', 'Position', [-1 0 0]) set(gca, 'Color', [0 0 0])
在command window輸入“L = 160*membrane(1,100);” 使用“surface”畫圖 去除edgecolor Create a matlab logo 在command window輸入“L = 160*membrane(1,100);” 使用“surface”畫圖 去除edgecolor 調整圖軸為X: [1 201], Y: [1 201], Z: [-53.4 160] 打兩道光:一為位置在[160 400 80]顏色為[0 0.8 0.8]的光, 另一為位置在[.5 -1 .4];顏色為[0.8 0.8 0]的光 更改物體顏色為[0.9 0.2 0.2] 更改背景顏色為黑色並將圖軸去除 (MATLAB會把執行結果顯示在command window上)
Thank you for your attention!!