Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 17 More Plotting Chapter 12 Matrices. Outline from Chapter 11 11.3 3D Plotting 11.4 Surface Plots 11.5 Interacting with Plotted Data.

Similar presentations


Presentation on theme: "Lecture 17 More Plotting Chapter 12 Matrices. Outline from Chapter 11 11.3 3D Plotting 11.4 Surface Plots 11.5 Interacting with Plotted Data."— Presentation transcript:

1 Lecture 17 More Plotting Chapter 12 Matrices

2 Outline from Chapter 11 11.3 3D Plotting 11.4 Surface Plots 11.5 Interacting with Plotted Data

3 Bar(x,y) >> help bar BAR Bar graph. BAR(X,Y) draws the columns of the M-by-N matrix Y as M groups of N vertical bars. The vector X must not have duplicate values. BAR(Y) uses the default value of X=1:M. For vector inputs, BAR(X,Y) or BAR(Y) draws LENGTH(Y) bars. The colors are set by the colormap. BAR(X,Y,WIDTH) or BAR(Y,WIDTH) specifies the width of the bars. Values of WIDTH > 1, produce overlapped bars. The default value is WIDTH=0.8 BAR(...,'grouped') produces the default vertical grouped bar chart. BAR(...,'stacked') produces a vertical stacked bar chart. BAR(...,LINESPEC) uses the line color specified (one of 'rgbymckw'). BAR(AX,...) plots into AX instead of GCA. H = BAR(...) returns a vector of handles to barseries objects. Use SHADING FACETED to put edges on the bars. Use SHADING FLAT to turn them off. Examples: subplot(3,1,1), bar(rand(10,5),'stacked'), colormap(cool) subplot(3,1,2), bar(0:.25:1,rand(5),1) subplot(3,1,3), bar(rand(2,3),.75,'grouped') See also hist, plot, barh, bar3, bar3h.

4 Example bar >> m=3 m = 3 >> n=5 n = 5 >> y = ones(m,n) y = 1 1 1 1 1 >> >> y(1,2) = 7 y = 1 7 1 1 1 1 1 1 1 1 >> y(2,1) = 2 y = 1 7 1 1 1 2 1 1 1 1 1 1 1 1 1 >> x=[1 2 3] x = 1 2 3 >> bar(x,y)

5 barh barh(x,y)

6 fill help fill FILL Filled 2-D polygons. FILL(X,Y,C) fills the 2-D polygon defined by vectors X and Y with the color specified by C. The vertices of the polygon are specified by pairs of components of X and Y. If necessary, the polygon is closed by connecting the last vertex to the first. If C is a single character string chosen from the list 'r','g','b', 'c','m','y','w','k', or an RGB row vector triple, [r g b], the polygon is filled with the constant specified color. If C is a vector the same length as X and Y, its elements are scaled by CAXIS and used as indices into the current COLORMAP to specify colors at the vertices; the color within the polygon is obtained by bilinear interpolation in the vertex colors. If X and Y are matrices the same size, one polygon per column is drawn. In this case, C is a row vector for "flat" polygon colors, and C is a matrix for "interpolated" polygon colors. If either of X or Y is a matrix, and the other is a column vector with the same number of rows, the column vector argument is replicated to produce a matrix of the required size. FILL(X1,Y1,C1,X2,Y2,C2,...) is another way of specifying multiple filled areas. FILL sets the PATCH object FaceColor property to 'flat', 'interp', or a colorspec depending upon the value of the C matrix. H = FILL(...) returns a column vector of handles to PATCH objects, one handle per patch. The X,Y,C triples can be followed by parameter/value pairs to specify additional properties of the patches. See also patch, fill3, colormap, shading.

7 Fill example >> x = [1 3 5 7 6 4 2] x = 1 3 5 7 6 4 2 >> y = [4 5 6 7 5 4 3] y = 4 5 6 7 5 4 3 >> fill(x,y,'b') >>

8 hist >> help hist HIST Histogram. N = HIST(Y) bins the elements of Y into 10 equally spaced containers and returns the number of elements in each container. If Y is a matrix, HIST works down the columns. N = HIST(Y,M), where M is a scalar, uses M bins. N = HIST(Y,X), where X is a vector, returns the distribution of Y among bins with centers specified by X. The first bin includes data between -inf and the first center and the last bin includes data between the last bin and inf. Note: Use HISTC if it is more natural to specify bin edges instead. [N,X] = HIST(...) also returns the position of the bin centers in X. HIST(...) without output arguments produces a histogram bar plot of the results. The bar edges on the first and last bins may extend to cover the min and max of the data unless a matrix of data is supplied. HIST(AX,...) plots into AX instead of GCA. Class support for inputs Y, X: float: double, single See also histc, mode.

9 Hist Example Code >> percentIncomeBracket = [14.5 10.1 8.2 7 6.4 6.5 6.1 5.9 5.1 4.3 7.3 18.6] percentIncomeBracket = Columns 1 through 6 14.5000 10.1000 8.2000 7.0000 6.4000 6.5000 Columns 7 through 12 6.1000 5.9000 5.1000 4.3000 7.3000 18.6000 >> hist(percentIncomeBracket) >> ylabel('Number of income brackets with this occupancy') >> xlabel('Percentage of population in income bracket')

10 Hist Example Plot

11 Loglog LOGLOG Log-log scale plot. LOGLOG(...) is the same as PLOT(...), except logarithmic scales are used for both the X- and Y- axes. See also plot, semilogx, semilogy.

12 Semilog Example x = [0 2 4 6 8 10 12 14 16] x = 0 2 4 6 8 10 12 14 16 >> y = [10^-14 10^-13 10^-10 10^-6 10^-6 10^-6 10^-6 10^-5 3*10^-5] y = 1.0e-004 * Columns 1 through 8 0.0000 0.0000 0.0000 0.0100 0.0100 0.0100 0.0100 0.1000 Column 9 0.3000 >> semilogy(x,y)

13 Semilogy Example Plot

14 pie help pie PIE Pie chart. PIE(X) draws a pie plot of the data in the vector X. The values in X are normalized via X/SUM(X) to determine the area of each slice of pie. If SUM(X) <= 1.0, the values in X directly specify the area of the pie slices. Only a partial pie will be drawn if SUM(X) < 1. PIE(X,EXPLODE) is used to specify slices that should be pulled out from the pie. The vector EXPLODE must be the same size as X. The slices where EXPLODE is non-zero will be pulled out. PIE(...,LABELS) is used to label each pie slice with cell array LABELS. LABELS must be the same size as X and can only contain strings. PIE(AX,...) plots into AX instead of GCA. H = PIE(...) returns a vector containing patch and text handles. Example pie([2 4 3 5],{'North','South','East','West'}) See also pie3. Reference page in Help browser doc pie

15 Example pie npIncomeBracket = percentIncomeBracket/100 npIncomeBracket = Columns 1 through 5 0.1450 0.1010 0.0820 0.0700 0.0640 Columns 6 through 10 0.0650 0.0610 0.0590 0.0510 0.0430 Columns 11 through 12 0.0730 0.1860 >> pie (npIncomeBracket)

16 polar >> help polar POLAR Polar coordinate plot. POLAR(THETA, RHO) makes a plot using polar coordinates of the angle THETA, in radians, versus the radius RHO. POLAR(THETA,RHO,S) uses the linestyle specified in string S. See PLOT for a description of legal linestyles. POLAR(AX,...) plots into AX instead of GCA. H = POLAR(...) returns a handle to the plotted object in H. Example: t = 0:.01:2*pi; polar(t,sin(2*t).*cos(2*t),'--r') See also plot, loglog, semilogx, semilogy. Reference page in Help browser doc polar

17 Example polar theta = linspace(0, 2*pi, 100); >> polar(theta, sin(2*theta).*cos(2*theta), '--r')

18 3D Plotting help plot3 PLOT3 Plot lines and points in 3-D space. PLOT3() is a three-dimensional analogue of PLOT(). PLOT3(x,y,z), where x, y and z are three vectors of the same length, plots a line in 3-space through the points whose coordinates are the elements of x, y and z. PLOT3(X,Y,Z), where X, Y and Z are three matrices of the same size, plots several lines obtained from the columns of X, Y and Z. Various line types, plot symbols and colors may be obtained with PLOT3(X,Y,Z,s) where s is a 1, 2 or 3 character string made from the characters listed under the PLOT command. PLOT3(x1,y1,z1,s1,x2,y2,z2,s2,x3,y3,z3,s3,...) combines the plots defined by the (x,y,z,s) fourtuples, where the x's, y's and z's are vectors or matrices and the s's are strings. Example: A helix: t = 0:pi/50:10*pi; plot3(sin(t),cos(t),t); PLOT3 returns a column vector of handles to lineseries objects, one handle per line. The X,Y,Z triples, or X,Y,Z,S quads, can be followed by parameter/value pairs to specify additional properties of the lines. See also plot, line, axis, view, mesh, surf.

19 3D Plotting howMany = 100; xs = linspace(1, 10, howMany); ys = linspace(1,30, howMany); zs = 24*xs.* xs.* ys +13 * ys.* ys.* xs +7 * xs +2* ys; plot3 (xs, ys, zs) xlabel('xlabel') ylabel('ylabel') zlabel('zlabel')

20 Surf-1 >> help surf SURF 3-D colored surface. SURF(X,Y,Z,C) plots the colored parametric surface defined by four matrix arguments. The view point is specified by VIEW. The axis labels are determined by the range of X, Y and Z, or by the current setting of AXIS. The color scaling is determined by the range of C, or by the current setting of CAXIS. The scaled color values are used as indices into the current COLORMAP. The shading model is set by SHADING. SURF(X,Y,Z) uses C = Z, so color is proportional to surface height. SURF(x,y,Z) and SURF(x,y,Z,C), with two vector arguments replacing the first two matrix arguments, must have length(x) = n and length(y) = m where [m,n] = size(Z). In this case, the vertices of the surface patches are the triples (x(j), y(i), Z(i,j)). Note that x corresponds to the columns of Z and y corresponds to the rows.

21 Surf-2 SURF(Z) and SURF(Z,C) use x = 1:n and y = 1:m. In this case, the height, Z, is a single-valued function, defined over a geometrically rectangular grid. SURF(...,'PropertyName',PropertyValue,...) sets the value of the specified surface property. Multiple property values can be set with a single statement. SURF(AX,...) plots into AX instead of GCA. SURF returns a handle to a surface plot object. AXIS, CAXIS, COLORMAP, HOLD, SHADING and VIEW set figure, axes, and surface properties which affect the display of the surface. See also surfc, surfl, mesh, shading.

22 Surface Plots-3 Imagine a cube, centered at the origin, with edges of length 2. The coordinates are: – 1,1,1 (D) – 1,1,-1 (H) – 1,-1,1 (C) – -1,1,1 (A) – 1,-1,-1 (G) – -1,-1,1 (B) – -1, 1,-1 (E) – -1,-1,-1 (F) There are 8 surface patches.

23 Surface patches ABCDA is a patch. The z-coordinate is +1 for each of these points. X(1) = 1, Y

24 Top patch %the patch that is the "top" has xs of 1, -1, ys of 1, -1 and zs =1 xs = [-1 1];ys=[-1 1]; zs = [ 1 1; 1 1]; subplot(1,2,1) surf(xs, ys, zs) axis equal

25 Top surface

26 Surface Plots - 4 %the patch that is the "top" has xs of 1, -1, ys of 1, -1 and zs =1 xs = [-1 1];ys=[-1 1]; zs = [ 1 1; 1 1]; subplot(1,2,1) surf(xs, ys, zs) axis equal grid on hold on %the patch that is the "bottom" has xs of 1, -1, ys of 1, -1 and zs =-1 xs = [-1 1];ys=[-1 1]; zs = [ -1 -1; -1 -1]; surf(xs, ys, zs) axis equal grid on xlabel('xlabel') ylabel('ylabel') zlabel('zlabel') shading interp view (-36, 44)

27 Top and Bottom Surfaces

28 Another Surface %the patch that has xs of 1, -1, ys of 1, -1 and zs =- 1,1 xs = [-1 1];ys=[1 1]; zs = [ -1 -1; 1 1]; surf(xs, ys, zs) axis equal grid on xlabel('xlabel') ylabel('ylabel') zlabel('zlabel') shading interp

29 Yet another surface %the patch that has xs of 1, 1, ys of 1, -1 and zs =-1,1 xs = [1 1];ys=[1 -1]; zs = [ -1 1; -1 1]; surf(xs, ys, zs) axis equal grid on xlabel('xlabel') ylabel('ylabel') zlabel('zlabel') shading interp view (-36, 44)

30 Meshgrid - 1 The x-y locations: mathematically, a lattice. In your textbook, the “plaid”. Variable z, has a value at every lattice point Example: hyperbolic paraboloid z= y 2 – x 2

31 Mesh >> help mesh MESH 3-D mesh surface. MESH(X,Y,Z,C) plots the colored parametric mesh defined by four matrix arguments. The view point is specified by VIEW. The axis labels are determined by the range of X, Y and Z, or by the current setting of AXIS. The color scaling is determined by the range of C, or by the current setting of CAXIS. The scaled color values are used as indices into the current COLORMAP. MESH(X,Y,Z) uses C = Z, so color is proportional to mesh height. MESH(x,y,Z) and MESH(x,y,Z,C), with two vector arguments replacing the first two matrix arguments, must have length(x) = n and length(y) = m where [m,n] = size(Z). In this case, the vertices of the mesh lines are the triples (x(j), y(i), Z(i,j)). Note that x corresponds to the columns of Z and y corresponds to the rows. MESH(Z) and MESH(Z,C) use x = 1:n and y = 1:m. In this case, the height, Z, is a single-valued function, defined over a geometrically rectangular grid. MESH(...,'PropertyName',PropertyValue,...) sets the value of the specified surface property. Multiple property values can be set with a single statement. MESH(AX,...) plots into AX instead of GCA. MESH returns a handle to a surface plot object. AXIS, CAXIS, COLORMAP, HOLD, SHADING, HIDDEN and VIEW set figure, axes, and surface properties which affect the display of the mesh. See also surf, meshc, meshz, waterfall.

32 Mesh - 2 xVector = linspace (-4, 4, 10); yVector = xVector; howManyXs = length(xVector); howManyYs = length(yVector); xPlane = ones(howManyXs, howManyYs); yPlane = ones(howManyXs, howManyYs); zValues = ones(howManyXs, howManyYs); for xValue = 1:howManyXs yPlane(xValue,:)=yVector end for yValue = 1:howManyYs xPlane(:,yValue) = xVector; for xValue = 1:howManyXs zValues(xValue, yValue) = yVector(yValue)*yVector(yValue)- xVector(xValue) * xVector(xValue) ; end mesh (xPlane, yPlane, zValues) axis tight title('hyperbolic paraboloid: z = y^2 - x^2') xlabel ('x') ylabel ('y') zlabel ('z')

33 Mesh - 3

34 Meshgrid-2 xVector = linspace (-4, 4, 10); yVector = xVector; [xP, yP] = meshgrid(xVector, yVector); zs = yP.* yP - xP.* xP; subplot (1,2,1) mesh (xPlane, yPlane, zValues) axis tight title('hyperbolic paraboloid: z = y^2 - x^2') xlabel ('x') ylabel ('y') zlabel ('z') subplot(1,2,2) mesh (xP, yP, zs)

35 Mesh/Meshgrid

36 Other variations subplot(1,2,2) surf (xP, yP, zs) hidden off

37 Shading - 1 subplot(1,2,2) surf (xP, yP, zs) shading flat axis tight

38 Shading - 2 subplot(1,2,2) surf (xP, yP, zs) shading interp axis tight


Download ppt "Lecture 17 More Plotting Chapter 12 Matrices. Outline from Chapter 11 11.3 3D Plotting 11.4 Surface Plots 11.5 Interacting with Plotted Data."

Similar presentations


Ads by Google