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.

Slides:



Advertisements
Similar presentations
CSE 123 Plots in MATLAB. Easiest way to plot Syntax: ezplot(fun) ezplot(fun,[min,max]) ezplot(fun2) ezplot(fun2,[xmin,xmax,ymin,ymax]) ezplot(fun) plots.
Advertisements

Introduction to Engineering MATLAB – 11 Plotting - 4 Agenda Multiple curves Multiple plot.
Plotting Selim Aksoy Bilkent University Department of Computer Engineering
Matlab Graphics S. Awad, Ph.D. M. Corless, M.S.E.E. E.C.E. Department University of Michigan-Dearborn Introduction to Matlab: 2D Graphics.
1 Chapter 4 Curve Plotting with MATLAB MATLAB provides some very powerful features for plotting and labeling curves. These operations can be performed.
Chapter 11 Above: Principal contraction rates calculated from GPS velocities. Visualized using MATLAB.
1. Overview 2. plot in 2D 3. Plot in 3D 4. Other possible charts 5. Engineers: label your plots! 6. Plots & Polynomial Plotting 11.
Digital Image Processing Lecture11: Histogram Processing.
MATLAB’s extensive, device-independent plotting capabilities are one of its most powerful features. They make it very easy to plot any data at any time.
Fall 2006AE6382 Design Computing1 Three Dimensional Plotting Learning Objectives –Understand the anatomy of a 3D plot –Basics of constructing plots in.
MATLAB GRAPHICS 2-D.
MATLAB Session 2 ES 156 Signals and Systems 2007 Harvard SEAS Prepared by Jiajun Gu.
[FX,FY,FZ,...] = GRADIENT(F,...) [FX,FY,FZ,…] is numerical gradient of matrix F Distance between grid points in X,Y,Z,… direction FX corresponds to dF/dx,
MATLAB Week 3 17 November Outline Graphics – Basic plotting – Editing plots from GUI – Editing plots from m-file – Advanced plotting commands.
Introduction to Matlab 332:202 Discrete Mathematics Spring 2007.
Plotting 1.Overview 2.plot in 2D 3.Plot in 3D 4.Other possible charts 5.Engineers: label your plots! 6.Plots & Polynomial.
Matlab intro The Environment
EPSII 59:006 Spring Outline Managing Your Session File Usage  Saving Workspace  Loading Data Files  Creating M-files More on Matrices Review.
 1999 BG Mobasseri1 8/29/2015 MATLAB GRAPHICS - PART II ADVANCED PLOTTING June 4, ‘99.
Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College.
Chapter 5 Review: Plotting Introduction to MATLAB 7 Engineering 161.
MATLAB INTRO CONTROL LAB1  The Environment  The command prompt Getting Help : e.g help sin, lookfor cos Variables Vectors, Matrices, and Linear Algebra.
6.094 Introduction to programming in MATLAB
Equation A statement that two mathematical expressions are equal.
Matlab Training Sessions 6,7: Plotting. Course Outline Weeks: 1.Introduction to Matlab and its Interface (Jan ) 2.Fundamentals (Operators) 3.Fundamentals.
CMPS 1371 Introduction to Computing for Engineers PLOTTING.
Plotting – 3-Dimensional. 3D Plots versus 2D Plots 3-dimensional plots, in contrast to 2-dimensional ones, has a third axis (often called the z-axis).
MATLAB Plotting With MATLAB 1. Two Dimensional Plots The xy plot is the most commonly used plot by engineers The independent variable is usually called.
Acute angle An angle with a measure less than 90 degrees.
MATLAB for Engineers, by Holly Moore. ISBN © 2007 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is.
Computational Methods of Scientific Programming Lecturers Thomas A Herring, Room A, Chris Hill, Room ,
Geometric Objects and Transformation
Lecture 10 2D plotting & curve fitting Subplots Other 2-D Plots Other 2-D Plots Curve fitting © 2007 Daniel Valentine. All rights reserved. Published by.
A L I MAM M OHAMMAD B IN S AUD I SLAMIC U NIVERSITY C OLLEGE OF S CIENCES D EPARTMENT OF M ATHEMATICS MATLAB 251 : MATH SOFTWARE Introduction to MATLAB.
Barak Shenhav Early Evolution Course 11 Feb 2001 MATLAB Visualization, Functions & Debugging.
Introduction to MATLAB Session 5 Simopekka Vänskä, THL 2010.
2D Routines in 3D. Outline Announcements –HW II--due Friday. 5PM HW1 & Cookie Grids & Meshes Representing f(x,y) Lines & Surfaces in 3D Survey.
Written by: Itzik Ben Shabat Technion - Israel Institute of Technology Faculty of Mechanical Engineering Laboratory for CAD & Lifecycle Engineering Lab.
Numerical Analysis 3D Plots. A numerical method is a technique for computing a numerical approximation of the solution to a mathematical problem.
Recap Chapter 5 “Plotting” Two Dimensional Plots Simple x-y Plots Titles, Labels and Grids Multiple Plots.
Recap Plots with More than one Line Plots of Complex Arrays Line, Color and Mark Style Axis Scaling and Annotating Plots Subplots Polar Plots Logarithmic.
EGR 106 Lecture 6 2-D Plotting Graphical presentation has become the standard method to show technical information. Engineers use plots to analyze, visualize,
1. Overview 2. plot in 2D 3. Plot in 3D 4. Other possible charts 5. Engineers: label your plots! 6. Plots & Polynomial Plotting 11.
ELG 3120 Lab 2 TAs Wei Zhang Ozgur Ekici (Section A) (Section B)
ENG 1181 College of Engineering Engineering Education Innovation Center MatLab – 2D Plots 2 MATLAB has many built-in functions and commands to create various.
Workshop 5 : Charts (cont’d). Bar Chart A chart with rectangular bars with the height (or length) of each bar being proportional to the actual values.
1 Lecture 5 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept.
GRAPHICS AND VISUALISATION WITH MATLAB UNIVERSITY OF SHEFFIELD CiCS DEPARTMENT Deniz Savas & Mike Griffiths May 2015.
MATLAB ® for Engineers, Holly Moore Fourth Edition, Global Edition © Pearson Education Limited 2015 All rights reserved. Figure 5.1 Simple Plot of Time.
More Matlab Graphics and GUI Graphics subplots some useful commands 3D graphics GUI GUI controls The callback property Other essential properties.
An Introduction to Programming in Matlab Emily Blumenthal
EEE 242 Computer Tools for Electrical Engineering
How to use MATLAB (using M-files) Double click this icon To start Matlab 6.5.
Session III Plotting in MATLAB Rajeev Madazhy Dept of Mechanical Engineering LSU MATLAB Tutorials.
Plotting ELEC 206 Computer Applications for Electrical Engineers Dr. Ron Hayne.
Plotting Chapter 5.
3D-Graphs A 3D surface is defined as: z = f(x, y)
Lecture 25.
Ch3 Graphics Overview of Plotting Editing Plots
2D Routines in 3D.
MATLAB How to use (using M-files) Double click this icon
MATLAB How to use (using M-files) Double click this icon
MatLab – 2D Plots 2 MATLAB has many built-in functions and commands to create various types of plots. Instructor notes: We start with an example of some.
Tutorial 2 SEG7550 Introduction to MATLAB II
MATLAB How to use (using M-files)
Advanced Plotting Techniques
Yang-Ming University, Taipei, Taiwan
Plotting Signals in MATLAB
How to Use MATLAB A Brief Introduction.
Introduction to Matlab
Presentation transcript:

Lecture 17 More Plotting Chapter 12 Matrices

Outline from Chapter D Plotting 11.4 Surface Plots 11.5 Interacting with Plotted Data

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.

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

barh barh(x,y)

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.

Fill example >> x = [ ] x = >> y = [ ] y = >> fill(x,y,'b') >>

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.

Hist Example Code >> percentIncomeBracket = [ ] percentIncomeBracket = Columns 1 through Columns 7 through >> hist(percentIncomeBracket) >> ylabel('Number of income brackets with this occupancy') >> xlabel('Percentage of population in income bracket')

Hist Example Plot

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.

Semilog Example x = [ ] x = >> 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 Column >> semilogy(x,y)

Semilogy Example Plot

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([ ],{'North','South','East','West'}) See also pie3. Reference page in Help browser doc pie

Example pie npIncomeBracket = percentIncomeBracket/100 npIncomeBracket = Columns 1 through Columns 6 through Columns 11 through >> pie (npIncomeBracket)

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

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

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.

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')

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.

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.

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.

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

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

Top surface

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)

Top and Bottom Surfaces

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

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)

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

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.

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')

Mesh - 3

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)

Mesh/Meshgrid

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

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

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