CMPS 1371 Introduction to Computing for Engineers PLOTTING.

Slides:



Advertisements
Similar presentations
Lab # 03- SS Basic Graphic Commands. Lab Objectives: To understand M-files principle. To plot multiple plots on a single graph. To use different parameters.
Advertisements

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.
Introduction to Graphing Using MATLAB. Line Graphs  Useful for graphing functions  Useful for displaying data trends over time  Useful for showing.
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. Overview 2. plot in 2D 3. Plot in 3D 4. Other possible charts 5. Engineers: label your plots! 6. Plots & Polynomial Plotting 11.
Reading Graphs and Charts are more attractive and easy to understand than tables enable the reader to ‘see’ patterns in the data are easy to use for comparisons.
MATLAB GRAPHICS 2-D.
MATLAB - Lecture 22A Two Dimensional Plots / Chapter 5 Topics Covered:
MATLAB Week 3 17 November Outline Graphics – Basic plotting – Editing plots from GUI – Editing plots from m-file – Advanced plotting commands.
Lecture 9 Plotting in 2-D Plotting in 2-D, Plotting Multiple Curves, Plotting with Figures, Plot Settings, Scaling, Legends © 2007 Daniel Valentine. All.
Let's zoom in on one corner of the coordinate plane
Introduction to Excel 2007 Bar Graphs & Histograms Psych 209 February 1st, 2011.
Chapter 5 Plotting Data Curve Fitting, Good Graphing Practices Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Using Charts in a Presentation Lesson 6. Software Orientation Charts can help your audience understand relationships among numerical values. The figure.
Introduction to Excel 2007 Part 3: Bar Graphs and Histograms Psych 209.
EPSII 59:006 Spring Outline Managing Your Session File Usage  Saving Workspace  Loading Data Files  Creating M-files More on Matrices Review.
Making Tables and Graphs with Excel The Basics. Where do my IV and DV go? Just like you would create a data table on paper, your IV goes in the leftmost.
Designing Effective Graphics Using MATLAB The Cain Project in Engineering and Professional Communication ENGINEERING SERIES.
 1999 BG Mobasseri1 8/29/2015 MATLAB GRAPHICS - PART II ADVANCED PLOTTING June 4, ‘99.
Chapter 5 Review: Plotting Introduction to MATLAB 7 Engineering 161.
PLOTS AND FIGURES DAVID COOPER SUMMER Plots One of the primary uses for MATLAB is to be able to create publication quality figures from you data.
ENG College of Engineering Engineering Education Innovation Center 1 2D Plots 1 in MATLAB Topics Covered: 1.Plotting basic 2-D plots The plot()
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Introduction to MATLAB 7 for Engineers Chapter 5 Advanced.
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.
Graphs Graphs are used to display data. They visually represent relationships between data. All graphs should have a title that identifies the variables.
MATLAB for Engineers, by Holly Moore. ISBN © 2007 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is.
Getting Started with TI-Interactive. TI-Interactive TI-Interactive can be used to create a variety of graphs. Scatter Plots, Line Plots, Histograms, Modified.
Graphing Data in Science Looking for a pattern. Why use a graph? Easier to analyze data Visualize patterns in the data Looks for trends.
Advanced Stata Workshop FHSS Research Support Center.
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.
Recap Sum and Product Functions Matrix Size Function Variance and Standard Deviation Random Numbers Complex Numbers.
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.
1 DKT 211 Basic Communication Engineering LAB # 1A : (Lecture 1) Introduction to Matlab  Basic Features  Scientific features  Array Operations  Script.
Barak Shenhav Early Evolution Course 11 Feb 2001 MATLAB Visualization, Functions & Debugging.
Introduction to MATLAB Session 5 Simopekka Vänskä, THL 2010.
GRAPHING NOTES Part 1. TYPES OF GRAPHS Graphs are used to illustrate what happens during an experiment. Bar graph - used for comparing data. Pie graph.
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,
EGR 115 Introduction to Computing for Engineers 2D Plotting – Part I Wednesday 17 Sept 2014 EGR 115 Introduction to Computing for Engineers.
1 Lecture 5 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept.
ENG College of Engineering Engineering Education Innovation Center 1 2D Plots 2 in MATLAB Topics Covered: 1.More about 2-D plots  Placing multiple.
GRAPHICS AND VISUALISATION WITH MATLAB UNIVERSITY OF SHEFFIELD CiCS DEPARTMENT Deniz Savas & Mike Griffiths May 2015.
Introduction to Engineering MATLAB – 9 Plotting - 2 Agenda Formatting plots.
MATLAB ® for Engineers, Holly Moore Fourth Edition, Global Edition © Pearson Education Limited 2015 All rights reserved. Figure 5.1 Simple Plot of Time.
NET 222: COMMUNICATIONS AND NETWORKS FUNDAMENTALS ( NET 222: COMMUNICATIONS AND NETWORKS FUNDAMENTALS (PRACTICAL PART) Lab 2 : potting to Matlab Networks.
More Matlab Graphics and GUI Graphics subplots some useful commands 3D graphics GUI GUI controls The callback property Other essential properties.
Let’s stay fresh with C. What does this print? void mystery(int * x); main(){ int a = 5; mystery(&a); printf("%d\n",a); } void mystery(int * x){ int y;
Using Graphs and Charts Organizing results from Scientific data.
Charts MOAC Lesson 6.
EEE 242 Computer Tools for Electrical Engineering
EGR 106 – Week 5 – 2-D Plots Question : Why do engineers use plots? Answer : To analyze, visualize, and present data. Matlab has many useful plotting options.
Lecture 17 More Plotting Chapter 12 Matrices. Outline from Chapter D Plotting 11.4 Surface Plots 11.5 Interacting with Plotted Data.
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.
Reading and Writing Image Files
Plotting Chapter 5.
3D-Graphs A 3D surface is defined as: z = f(x, y)
Lecture 25.
Ch3 Graphics Overview of Plotting Editing Plots
Lecture 25: Exploring data
Lecture 10 2D plotting & curve fitting
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.
MATLAB How to use (using M-files)
Introduction to MATLAB Plotting LAB 3
Plotting Signals in MATLAB
Presentation transcript:

CMPS 1371 Introduction to Computing for Engineers PLOTTING

Plotting

Two Dimensional Plots The xy plot is the most commonly used plot by engineers The independent variable is usually called x The dependent variable is usually called y

Consider xy data time, secDistance, Ft Time is the independent variable and distance is the dependent variable

Plot function Define x and y and call the plot function You can use any variable name that is convenient for the dependent and independent variables

Engineers always add … Title X axis label, complete with units Y axis label, complete with units Often it is useful to add a grid

Multiple plots MATLAB overwrites the figure window every time you request a new plot To open a new figure window use the figure function – for example figure(2) Create plot on same graph hold on Freezes the current plot, so that an additional plot can be overlaid When you use this approach the additional line is drawn in blue – the default drawing color

The first plot is drawn in blue

The hold on command freezes the plot The second line is also drawn in blue, on top of the original plot To unfreeze the plot use the hold off command

Same graph You can also create multiple lines on a single graph with one command Using this approach each line defaults to a different color

Each set of ordered pairs will produce a new line

Variations If you use the plot command with a single matrix, MATLAB plots the values versus the index number

Variations If you want to create multiple plots, all with the same x value you can… Use alternating sets of ordered pairs plot(x,y1,x,y2,x,y3,x,y4) Or group the y values into a matrix z=[y1,y2,y3,y4] plot(x,z)

Alternating sets of ordered pairs Matrix of Y values

Peaks The peaks(100) function creates a 100x100 array of values. Since this is a plot of a single variable, we get 100 different line plots

Line, Color and Mark Style You can change the appearance of your plots by selecting user defined line styles color mark styles Try using: help plot for a list of available styles

Available choices Line TypeIndicatorPoint TypeIndicatorColorIndicator solid-point.blueb dotted:circleogreeng dash-dot-.x-markxredr dashed--plus+cyanc star*magentam squaresyellowy diamonddblackk triangle downv triangle up^ triangle left< triangle right> pentagramp hexagramh

Specify your choices in a string plot(x,y,‘linestyle markstyle color') strings are identified with a tick (apostrophe) mark if you don’t specify style, a default is used line style – none mark style – none color – blue Consider:plot(x,y,’:ok’) the : means use a dotted line the o means use a circle to mark each point the letter k indicates that the graph should be drawn in black (b indicates blue)

dotted line circles black

specify the drawing parameters for each line after the ordered pairs that define the line

Axis scaling MATLAB automatically scales each plot to completely fill the graph If you want to specify a different axis – use the axis command axis([xmin,xmax,ymin,ymax]) Lets change the axes on the graph we just looked at

Use the axis function to override the automatic scaling

Annotating Your Plots You can also add legends textbox Of course you should always add title axis labels

Improving your labels You can use Greek letters in your labels by putting a backslash (\) before the name of the letter. For example: title(‘\alpha \beta \gamma’) creates the plot title α β γ To create a superscript use curly brackets title(‘x^{2}’) gives x 2

Subplots The subplot command allows you to subdivide the graphing window into a grid of m rows and n columns subplot(m,n,p) rowscolumns location

subplot(2,2,1) 2 rows 2 columns

2 rows and 1 column

Other Types of 2-D Plots Polar Plots Logarithmic Plots Bar Graphs Pie Charts Histograms X-Y graphs with 2 y axes Function Plots

Polar Plots Some functions are easier to specify using polar coordinates than by using rectangular coordinates Use polar(x,y) For example the equation of a circle is y=sin(x) in polar coordinates

Logarithmic Plots A logarithmic scale (base 10) is convenient when a variable ranges over many orders of magnitude, because the wide range of values can be graphed, without compressing the smaller values. data varies exponentially

Plots plot(x,y) – uses a linear scale on both axes semilogy(x,y) uses a log 10 scale on the y axis semilogx(x,y) uses a log 10 scale on the x axis loglog(x,y) use a log 10 scale on both axes

Bar Graphs and Pie Charts MATLAB includes a whole family of bar graphs and pie charts bar(x) – vertical bar graph barh(x) – horizontal bar graph bar3(x) – 3-D vertical bar graph bar3h(x) – 3-D horizontal bar graph pie(x) – pie chart pie3(x) – 3-D pie chart

Bar Graphs

Histograms A histogram is a plot showing the distribution of a set of values Defaults to class size of 10

X-Y Graphs with Two Y Axes Sometimes it is useful to overlay two x-y plots onto the same figure. However, if the order of magnitude of the y values are quite different, it may be difficult to see how the data behave.

Scaling Depends on the largest value plotted Example Its difficult to see how the blue line behaves, because the scale isn’t appropriate

plotyy function for 2 y-axis The plotyy function allows you to use two scales on a single graph

Function Plots Function plots allow you to use a function as input to a plot command, instead of a set of ordered pairs of x-y values fplot('sin(x)',[-2*pi,2*pi]) function input as a string range of the independent variable – in this case x

Three Dimensional Plotting Line plots Surface plots Contour plots

Three Dimensional Line Plots These plots require a set of order triples ( x-y-z values) as input Use plot3(x,y,z) The z-axis is labeled the same way the x and y axes are labeled

MATLAB uses a coordinate system consistent with the right hand rule

Just for fun try the comet3 function, which draws the graph in an animation sequence comet3(x,y,z) If your animation draws too slowly, add more data points For 2-D line graphs use the comet function

Surface Plots Represent x-y-z data as a surface mesh - meshplot surf – surface plot Can use both mesh and surface plots to good effect with a single two dimensional matrix

The x and y coordinates are the matrix index numbers

Surf plots surf plots are similar to mesh plots they create a 3-D colored surface instead of an open mesh syntax is the same

Shading There are several shading options shading interp shading flat faceted flat is the default You can also adjust the color scheme with the color map function

Colormaps autumnbonehot springcolorcubehsv summercoolpink wintercopperprism jet (default)flagwhite

Contour Plots Contour plots use the same input syntax as mesh and surf plots They create graphs that look like the familiar contour maps used by hikers

Variations A more complicated surface can be created by calculating the values of z, instead of just defining them We’ll need to use the meshgrid function to create 2-D input arrays – which will then be used to create a 2-D result Creates an x by y matrix

Another 3-D graph Try this example and see what you get >> g = 0:0.2:10; >> [x,y] = meshgrid(g); >> z = 2*sin(sqrt(x.^2 + y.^2)); >> mesh(z);

Cowboy Hat Try this code >> [X,Y]=meshgrid(-1.5:.1:1.5,-1.5:.1:1.5); >> Z=sin(3*X.^2+2*Y.^2)./(X.^2+Y.^2); >> mesh(Z)

Cowboy Hat

Combine 3-D Plots Try this code >> [s,t]=meshgrid(0:.02*pi:2*pi,0:.02*pi:pi); >> [u,v]=meshgrid(0:.05*pi:2*pi,-2:.2:2); >> surf(3*cos(s).*sin(t),2*sin(s).*sin(t),cos(t)) >> axis equal; >> hold on; >> surf(cos(u),sin(u),v)

ellipsoid and cylinder

Editing Plots from the Menu Bar In addition to controlling the way your plots look by using MATLAB commands, you can also edit a plot once you’ve created it using the menu bar Another demonstration function built into MATLAB is >> sphere

Menu Bar Once you’ve created a plot you can adjust it using the menu bar In this picture the insert menu has been selected Notice you can use it to add labels, legends, a title and other annotations

Select Edit-> Axis Properties from the menu tool bar Change the Aspect Ratio Explore the property editor to see some of the other ways you can adjust your plot interactively Select More Properties to pull up the Inspector

Note If you adjust a figure interactively, you’ll lose your improvements when you rerun your program

Creating plots from the workspace

Plotting options MATLAB will suggest plotting options and create the plot for you