Creating a Plot The plot function can take one or more inputs; e.g. plot (x, y) or plot (y) Note that in the two-argument version, the vectors x and.

Slides:



Advertisements
Similar presentations
Introduction to Engineering MATLAB – 11 Plotting - 4 Agenda Multiple curves Multiple plot.
Advertisements

Plotting Selim Aksoy Bilkent University Department of Computer Engineering
Lecture (4) Plotting & Programming (1) Eng. Osama Talaat 1.
2D Plots 1 ENGR 1181 MATLAB 12.
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.
Introduction to MATLAB for Biomedical Engineering BME 1008 Introduction to Biomedical Engineering FIU, Spring 2015 Lesson 2: Element-wise vs. matrix operations.
1. Overview 2. plot in 2D 3. Plot in 3D 4. Other possible charts 5. Engineers: label your plots! 6. Plots & Polynomial Plotting 11.
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.
MA/CS375 Fall MA/CS 375 Fall 2002 Lecture 4.
MATLAB GRAPHICS 2-D.
MATLAB - Lecture 22A Two Dimensional Plots / Chapter 5 Topics Covered:
EGR106 Week 6 MATLAB FILES Two Dimensional Plots Multiple Plots
Vectors and Plotting Selim Aksoy Bilkent University Department of Computer Engineering
MATLAB Week 3 17 November Outline Graphics – Basic plotting – Editing plots from GUI – Editing plots from m-file – Advanced plotting commands.
EGR106 Week 4 Two Dimensional Plots Multiple Plots Plot Formatting Homework.
Introduction to Matlab 332:202 Discrete Mathematics Spring 2007.
Plotting. Basic Plotting Two vectors of x and y values needed. Vectors need to be of the same length, but not necessarily of the same geometry. For example,
Introduction to Matlab Jianguo Wang CSSCR September 2009.
An introduction to Plotting in MATLAB Rikard Johansson Department of Biomedical Engineering (IMT) Linköping University
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()
1 "A picture is worth a thousand words." Graphical representation is useful for: Error detection - you can locate outliers in a dataset, program bugs,
„  1999 BG Mobasseri1 9/18/2015 June 2 GRAPHICS IN MATLAB- PART I BASIC PLOTTING.
ELG 3120 Signal and System Analysis 1 Introduction to MATLAB TAs Wei Zhang Ozgur Ekici (Section A)(Section B) ELG 3120 Lab Tutorial 1.
INTRODUCTION TO MATLAB LAB# 01
COMP 116: Introduction to Scientific Programming Lecture 5: Plotting, Scripts and publishing.
MAE 1202: AEROSPACE PRACTICUM An Introduction to MATLAB: Part 2 Mechanical and Aerospace Engineering Department Florida Institute of Technology Developed.
ENG 1181 College of Engineering Engineering Education Innovation Center MATLAB – 2D Plots 1 Go to the class drive: ---> MatLab - Graphing ---> Seed Files.
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.
Matlab Screen  Command Window  type commands  Current Directory  View folders and m-files  Workspace  View program variables  Double click on a.
Plot (x-values, y-values) >> x = linspace (-3, 3, 20); >> x = linspace (-3, 3, 20); >> y = 2*x – 1; >> y = 2*x – 1; >> plot (x, y) >> plot (x, y)
Recap Chapter 5 “Plotting” Two Dimensional Plots Simple x-y Plots Titles, Labels and Grids Multiple Plots.
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.
Introduction to Matlab  Matlab is a software package for technical computation.  Matlab allows you to solve many numerical problems including - arrays.
ELG 3120 Lab 2 TAs Wei Zhang Ozgur Ekici (Section A) (Section B)
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.
Introduction to Engineering MATLAB – 9 Plotting - 2 Agenda Formatting plots.
NET 222: COMMUNICATIONS AND NETWORKS FUNDAMENTALS ( NET 222: COMMUNICATIONS AND NETWORKS FUNDAMENTALS (PRACTICAL PART) Lab 2 : potting to Matlab Networks.
CS100A, Fall 1998, Lecture 191 CS100A, Fall 1998 Lecture 19, Thursday Nov 05 Matlab Concepts: Matlab arrays Matlab subscripting Matlab plotting.
CS100A, Fall 1998, Lecture 201 CS100A, Fall 1998 Lecture 20, Tuesday Nov 10 More Matlab Concepts: plotting (cont.) 2-D arrays Control structures: while,
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.
How to use MATLAB (using M-files) Double click this icon To start Matlab 6.5.
Computer Application in Engineering Design
Introduction to Mat lab
Plotting Chapter 5.
3D-Graphs A 3D surface is defined as: z = f(x, y)
Lecture 25.
Ch3 Graphics Overview of Plotting Editing Plots
Course Information Do not rely on color to distinguish curves (due to black-white printout). Use different line styles to distinguish curves (solid, dashed,
Lecture 25: Exploring data
Matrices and Arrays.
MatLab – Palm Chapter 5 2-D & 3-D Plots
Net 222: Communications and networks fundamentals (Practical Part)
Net 222: Communications and networks fundamentals (Practical Part)
Net 222: Communications and networks fundamentals (Practical Part)
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.
Introduction to MATLAB Programming
MATLAB How to use (using M-files)
Introduction to MATLAB Plotting LAB 3
Plotting Signals in MATLAB
Introduction to MATLAB Programming
Announcements P3 due today
Introduction to Matlab
Presentation transcript:

Creating a Plot The plot function can take one or more inputs; e.g. plot (x, y) or plot (y) Note that in the two-argument version, the vectors x and y must be of the same length. Example: y = [1 4 9 16 25 36] % length is 6 x1= [1 2 3 4 5 6 ] % length is 6 plot(x1,y) % this is ok Example: y = [1 4 9 16 25 36] % length is 6 x2= [1 2 3 4] % length is 4 plot(x2,y) will result in an error due to unequal lengths source: HKA & AAB

Creating a Plot If only one argument is used, it will become the vertical axis. The horizontal axis will be the corresponding index of the argument. y = [1 4 9 16 25 36] % length is 6 plot(y) % this is ok % Horizontal axis will be the index vector [1 2 3 4 5 6] x = [1 2 3 4] % length is 4 plot(x) % this is ok % Horizontal axis will be the index vector [1 2 3 4] MAKE SURE YOU GET THIS source: HKA & AAB

{ Exercise Plot a sin function: x = 0 : pi/100 : 2*pi; y = sin(x); plot(x,y) { x goes from 0 to 2π in steps of π/100 Now try: x = 0 : pi/4 : 2*pi; y = sin(x); plot(x,y) why isn’t the curve smooth? source: HKA & AAB

Plot Title and Labels To add title and labels to the plot: xlabel('x = 0:2\pi'); ylabel('Sine of x'); title('Plot of the Sine Function','FontSize',12) Remember, help plot is always useful this is how to write π in a character string or label, ie. not code source: HKA & AAB

Specifying Line Styles and Colours It is possible to specify colour, line styles, and markers (such as plus signs or circles) when you plot your data using the plot command plot (x, y, ‘<color_style_marker>’) <color_style_marker> can be any of: Colour signs: 'c' 'r' 'y' 'g' 'b' 'w' 'k' Line style strings: '-' for solid, '--' for dashed, ':' for dotted, '-.' for dash-dot The marker types are '+', 'o', '*', and 'x', and the filled marker types are 's' for square, 'd' for diamond, etc. plot (x, y, 'r') plot (x, y, 'r*') % note the asterisk * after the r source: HKA & AAB

Multiple Data Sets in One Graph Multiple x-y pair arguments create multiple graphs with a single call to plot. Example: x = 0:pi/100:2*pi; y = sin(x); y2 = sin(x-.25); y3 = sin(x-.5); plot(x,y,x,y2,x,y3); legend command helps identify plots Use single quotes to indicate the label of each dataset legend('sin(x)','sin(x-.25)','sin(x-.5)'); >> help hold on >> help line source: HKA & AAB

Figure Windows Matlab automatically opens a figure window if one does not exist; but you can open and name as many as you want – but too many can slow down the system >> figure (n) opens a new figure with n representing the number in the title bar (or changes the figure we handle – see below) >> close(n) >> close all >> clf >> shg % brings the current figure forward source: HKA & AAB

Controlling the Axis The axis command provides a number of options for setting the scaling, orientation, and aspect ratio of graphs For axis limits, >> axis([xmin xmax ymin ymax]) >>xlim([xmin xmax]); ylim([ymin ymax]) Can make axis visible/invisible, >> axis on >> axis off The grid command toggles grid lines on and off >> grid on; >> grid off Check: >> help plot3 % try 3D graph of sine & cosine >> axis equal % to get the circle source: HKA & AAB

Multiple Plots in One Figure The subplot command enables displaying multiple plots in the same window or print them on the same piece of paper >> subplot(m,n,i) partitions the figure window into an m- by-n matrix of small subplots and selects the ith subplot for the current plot an example: plot two figures, one that shows the sine and cosine function next to each other and one that shows them one under the other.. source: HKA & AAB

Adding text to a plot The text function simply writes text on the plot based on the x-y coordinates. text(x,y, 'your text here') Options for help: >> help text >> help gtext Matlab also supports the TeX typesetting language xlabel(‘\theta’); xlabel('-\pi \leq t \leq \pi'); source: HKA & AAB

Handle Graphics Handle Graphics refers to a system of graphics objects that MATLAB uses to implement graphing and visualization functions For example, the following statement creates a figure with a white background colour and without displaying the figure toolbar >> figure('Color','white','Toolbar','none') >> h=figure('Color','white','Toolbar','none') source: HKA & AAB

Handle Graphics The following statements create a graph and return a handle to h >> x = 1:10; y = x.^3; h = plot(x,y); You can use the handle h to set the properties of the object (figure). For example, you can set its Colour property: >> set(h,'Color','red') You can also specify properties when you call the plotting function >> h = plot(x,y,'Color','red'); When you query the object properties, >> get(h,'LineWidth') >> get(h) >> h2=gcf % get current figure >> h3=gca % get current axis (also an ‘object’) source: HKA & AAB

Handle Graphics >> figure(1) >> x = -pi:pi/10:pi; >> y = tan(sin(x)) - sin(tan(x)); >> plot(x,y,'-rs') >> set(gca,'XTick',-pi:pi/2:pi) >> set(gca,'XTickLabel',{'-pi','-pi/2','0','pi/2','pi'}) >> xlabel('-\pi \leq \Theta \leq \pi') >> ylabel('func(\Theta)') >> title('Plot of Weird Function') >> text(-pi/4,sin(-pi/4), '\leftarrow Look Here') source: HKA & AAB

Figures: Saving and Copying Can save from File menu of Figure Can copy from File menu of Figure >> help openfig You can save the variables in your workspace using the Save Workspace As item in the figure File menu. You can reload saved data using the Import Data item in the figure File menu You can generate MATLAB code that recreates a figure and the graph it contains by selecting the Generate M-File item from the figure File menu source: HKA & AAB

Wrapping up >> help graphics Use the in-built documentation to place what you have done today into perspective, and to discover more advanced graphics available to you. >> edit graf2d source: HKA & AAB

Exercises source: HKA & AAB

Exercise Clear the workspace (clear all) and close all open figure windows (close all). Create x = [-2*pi:0.1:2*pi]; Plot x against cos(x) in figure 1 using the default settings (simple line plot, solid blue line) Now replot x against cos(x) in figure 1 but with a solid black line Open figure 10 and plot x against sin(x) as a set of green points only (with no line joining the points ) Close figure 10, keeping figure 1 open, and reselect figure 1 In figure 1, whilst keeping the black line, overplot the figure with red circles where the points are Add to the existing plot sin(x) as a dashed blue line Change the x-axis to show only the range 0 to pi. Add a plot title called 'My favourite plot', an x-axis label called 'x-axis' and a y-axis label called 'y-axis‘ Change the x-axis tic marks and labels to go from 0 to pi in steps of pi/4 source: HKA & AAB

Exercise: Multiple Plots in One Figure Open TBmatlabdata.m and read comments. Run script or type filename on command line Create a pie chart in position 1 of a 2x2 grid showing the proportion of total measles, mumps and chickenpox cases. Add labels to each category and a title. Hint: pie([ sum(A) sum(B) sum(C)], {‘labelA’, ‘labelB’, ‘labelC’}) Create a stacked bar chart in position 2 of a 2x2 grid for measles, mumps and chickenpox. Add labels, legend & title. bar([row vector of 12 steps], [row vector of 3 disease variable names], 'stacked'); Create a stem chart in position 3 of a 2x2 grid of ‘years’ vs ‘cases’ of tuberculosis. Add labels & title. Create the line plot in position 4 of a 2x2 grid of ‘years’ vs ‘infection rate’. Add labels & title.

Exercise: Multiple Plots in One Figure