Motivation The interactive tools: Drawing commands Interactive figure manipulation The programmer point of view: Introduction to objects and their handles.

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

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.
Slide deck by Dr. Greg Reese Miami University MATLAB An Introduction With Applications, 5 th Edition Dr. Amos Gilat The Ohio State University Chapter 5.
1. Overview 2. plot in 2D 3. Plot in 3D 4. Other possible charts 5. Engineers: label your plots! 6. Plots & Polynomial Plotting 11.
MA/CS375 Fall MA/CS 375 Fall 2002 Lecture 4.
MATLAB GRAPHICS 2-D.
Introduction to MATLAB Northeastern University: College of Computer and Information Science Co-op Preparation University (CPU) 10/27/2003.
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.
Lecture 9 Plotting in 2-D Plotting in 2-D, Plotting Multiple Curves, Plotting with Figures, Plot Settings, Scaling, Legends © 2007 Daniel Valentine. All.
SPSS Statistical Package for the Social Sciences is a statistical analysis and data management software package. SPSS can take data from almost any type.
Introduction to Excel 2007 Part 3: Bar Graphs and Histograms Psych 209.
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()
CMPS 1371 Introduction to Computing for Engineers PLOTTING.
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.
The Hong Kong Polytechnic University Industrial Centre 1 MatLAB Lesson 3 : Graphics Edward Cheung Room W311g 2008m.
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.
ELG 3120 Signal and System Analysis 1 Introduction to MATLAB TAs Wei Zhang Ozgur Ekici (Section A)(Section B) ELG 3120 Lab Tutorial 1.
The introduction to SPSS Ⅱ.Tables and Graphs for one variable ---Descriptive Statistics & Graphs.
MATLAB and SimulinkLecture 51 To days Outline Linear Equations ODE Integration Handle Graphics. Exercises on this days topics.
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.
Lecture 2 - Matlab Introduction CVEN 302 June 5, 2002.
SUNY-New Paltz Computer Simulation Lab Electrical and Computer Engineering Department SUNY – New Paltz “Lecture 9”
Barbara/Pratik/Yu. Outline Matlab desktop M-files Variables Arrays Plots.
Barak Shenhav Early Evolution Course 11 Feb 2001 MATLAB Visualization, Functions & Debugging.
A lesson approach © 2011 The McGraw-Hill Companies, Inc. All rights reserved. a lesson approach Microsoft® Excel 2010 © 2011 The McGraw-Hill Companies,
Written by: Itzik Ben Shabat Technion - Israel Institute of Technology Faculty of Mechanical Engineering Laboratory for CAD & Lifecycle Engineering Lab.
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,
Introduction to Matlab  Matlab is a software package for technical computation.  Matlab allows you to solve many numerical problems including - arrays.
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.
Handle Graphics and 1D Primitives Some Handel graphics.
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.
An Introduction to Programming in Matlab Emily Blumenthal
Beginning Programming for Engineers Animation. Special matrix functions >> clear >> ones(2,3) >> zeros(3,5) >> ones(2) >> zeros(3) >> eye(4) >> magic(4)
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.
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.
Plotting Chapter 5.
Lecture 25.
Ch3 Graphics Overview of Plotting Editing Plots
Lecture 25: Exploring data
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.
Plotting Multiple Graphs In The Same Plot
MATLAB How to use (using M-files)
Introduction to MATLAB Plotting LAB 3
Yang-Ming University, Taipei, Taiwan
Plotting Signals in MATLAB
Presentation transcript:

Motivation The interactive tools: Drawing commands Interactive figure manipulation The programmer point of view: Introduction to objects and their handles Invoking and manipulating graphics objects

The interactive tools >> x = -5:0.05:5; % [ …… ] >> y = sin(x.^2); >> plot(x,y)

none

The axes is contained within the figure. A figure may have more than one axes.

The plot is contained within the axes. An axes may have more than one plot.

>> y2= 1./(1+exp(-x)); >> hold Current plot held >> plot(x,y2,'color','k','lineStyle','-.')

>> y2= 1./(1+exp(-x)); >> hold Current plot held >> plot(x,y2,'color','k','lineStyle','-.') Property-name, property value pair

>> y2= 1./(1+exp(-x)); >> hold Current plot held >> plot(x,y2,'color','k','lineStyle','-.') Property-name, property value pair

dash-dot line -. dotted line : dashed line -- solid line (default) - Line Style Specifier six-pointed star (hexagram)h five-pointed star (pentagram)p triangle pointing left< triangle pointing right> triangle pointing downwardv triangle pointing upward^ diamondd squares crossx point. asterisk* circleo Plus sign+ Marker typeSpecifier whitew blackk yellowy magentam cyanc blueb greeng Redr ColorSpecifier

Alternative format: >> x=[ ]; >> y=[ ]; >> p2=plot(x,y,'or:’);

Alternative format: >> x=[ ]; >> y=[ ]; >> p2=plot(x,y,'or:’); Marker Color LineStyle There are more alternative formats Use MATLAB help. Consult the property inspector.

Specialized 2D plots Bars Histograpms Stair Stem Scatter Error bars Area Pie charts contour

Specialized 3D plots plot3 mesh surf Use MATLAB help and demos.

The programmer’s point of view: Graphic Objects Handles Properties

Graphic Object (figure, axes, text, line etc.) handle

Graphic Object (figure, axes, text, line etc.) handle properties

Many objects may exist simultaneously

We use the handles to pick an object and manipulate it.

An object may have more than one handle

Objects may contain other objects

Everything inside a figure window is a graphic object The figure window itself is a graphic object All plots in MATLAB are made of graphic objects All graphic objects have properties that control the way they look and behave Graphic object: any element as defined by the set of its properties that constitute part of a figure

>> t = -pi:0.05:pi; >> x = cos(3*t)*1./(1+exp(-t)); >> y = sin(3*t)*1./(1+exp(-t)); >> p = plot(x,y) p = A handle

Objects The plot The axes The figure ? Handles p is the plots handle ?

>>set(p,'color','r') >>set(p,'lineWidth',4) handle

>>set(p,'color','r') >>set(p,'lineWidth',4) property names

>>set(p,'color','r') >>set(p,'lineWidth',4) How would I know what properties does the plot have? property values

>> get(p) Color: [1 0 0] EraseMode: 'normal' LineStyle: '-' LineWidth: 4 Marker: 'none' MarkerSize: 6 MarkerEdgeColor: 'auto' MarkerFaceColor: 'none' XData: [1x126 double] YData: [1x126 double] ZData: [1x0 double] BeingDeleted: 'off' ButtonDownFcn: [] Children: [0x1 double] Clipping: 'on' CreateFcn: [] DeleteFcn: [] BusyAction: 'queue' HandleVisibility: 'on' HitTest: 'on' Interruptible: 'on' Selected: 'off' SelectionHighlight: 'on' Tag: '' Type: 'line' UIContextMenu: [] UserData: [] Visible: 'on' Parent: DisplayName: '' XDataMode: 'manual' XDataSource: '' YDataSource: '' ZDataSource: ''

>> p_parent=get(p,'parent') p_parent = handle

property name >> p_parent=get(p,'parent') p_parent =

property value >> p_parent=get(p,'parent') p_parent =

>> p_parent=get(p,'parent') p_parent = p_parent is a handle. Of what? >> get(p_parent,'type') ans = axes

>> get(p_parent,'children') ??? ans = >> p ans =

>> set(p_parent,'xcolor','b'); >> set(p_parent,'ycolor','b'); What about the title? >> title=get(p_parent,'title') title = >> get(title,'type') ans = text

>> set(p_parent,'xcolor','b'); >> set(p_parent,'ycolor','b'); What about the title? >> title=get(p_parent,'title') title = >> get(title,'type') ans = text >> set(title,'string','Spiral') >> set(title,'color','b')

Lets add another line Ooooops… >> x1 = -cos(3*t)*1./(1+exp(-t)); >> y1 = -sin(3*t)*1./(1+exp(-t)); >> plot(x1,y1) >> lines = get(p_parent,'children') lines = >> blue=lines(1) blue = >> set(blue,'lineWidth',4)

Alternatively: >> findobj('color','b') ans =

Who is the title’s parent? Who are the title’s children? Who is the axes` parent? Who is the figure’ parent?

Graph Objects Phylogeny This hierarchy is based on the interdependency of objects. A line can only be plotted inside an Axes. A figure contains Axes and so on.

Graph Objects Phylogeny parent

Graph Objects Phylogeny children

…in the beginning there is only the root object…. Hello, I am the root object Although I am the root I always got a 0 as my handle I know and control many important things… Type get(0) to see all my properties

What is the difference between a handle and “simple variable”? >> a = [ ]; >> b = a; >> b(3)=9 b = >> a a = >> get(title,'String') ans = Spiral >> ttt = title; >> set(ttt,'string','Red wide spiral') >> get(title,'String') ans = Red wide spiral

handle right_handle = handle

The subplot command Present simultaneously several pieces of information that when displayed on a single plot may confuse the reader Display and image and quantification Let’s see an example

x=linspace(0,3,500); plot(x,1./(x-1).^2+3./(x-2).^2) grid on %Change zooming ylim([0 50])

>>x=linspace(0,3,500); >>a(1)=subplot(1,2,1);%1 rows, 2 cols use first axis >>plot(x,1./(x-1).^2+3./(x-2).^2) >>a(2)=subplot(1,2,2 );%1 rows, 2 cols use second axis >>plot(x,1./(x-1).^2+3./(x-2).^2) >>ylim([0 50]) >>set(a,'XGrid','on','YGrid','on')

The general synopsis of subplot is subplot (n,m,p) where n is the number of rows m is the number of columns p identifies the specific subplot. Starting from the top left axes and counting across rows How to use the subplot command >>subplot(1,2,2)

MATLAB has an text interpreter named T E X very similar to LAT E X. format mathematical expressions and Greek letters to display nicely both in the screen and in printed material we use a backslash “\” followed by either a symbol identifier, or a string modifier We can limit the extent of string formatting by placing the string inside curly braces {…} To create the following formatted string f()=sin() We write: {\itf(\tetha)}=sin{\it(\tetha)}

A little more elaborated example: The most useful string modifiers are: \it changes text to italics \rmchanges text to normal ^superscript _underscript

Bar plots bar and barh create vertical and horizontal bar graph respectively When you use bar(Y) where Y is a matrix, rows are treated as groups. Use bar(x,Y) to center the bars at the places specified by x

>>x=[10,20,30]; >>y=[ ]; >>bar(x,y) >>title('Vertical bar graph');

>>bar(x,y,'stacked')

Histograms Use hist(X,[bins]) to create an histogram (one per column of X) By default the count of the data is done in 10 bins You can change this by passing a second argument to hist –Scalar => tells the number of bins –Vector => tell the center of each bin

Y(:,1)=randn(10000,1); Y(:,2)=randn(10000,1)+10; hist(Y,20) title('histogram with 20 bins');

As we saw hist plots the count (i.e. the number of elements in each category) What if we want to plot the frequencies instead? Use [n,x]=hist(X,[bins]) –n will hold the # of elements of each bin –x will hold the center value of each bin

>> [n,x]=hist(Y,20) >> freqN=n./repmat(sum(n),length(n),1) % freqN=n/10000 >> bar (x,freqN)

Stair plots Commonly used in digital signal processing and statistical analysis When we sample data at a given rate, we have no information about what is going on between two consecutive samples

>> x=-2:0.1:2; >> y=normpdf([-2:0.1:2],0,1); >> stairs(x,y) >> title('Stair graph')

Error bars Error bars can be added to plots with the help of the errorbar function. The synopsis of this function is errorbar(x,y,l,u,[formatting string]) x,y,l,u are all vertors of the same size draws a marker on the point specified by the x,y and add bars of the size [ y+u(i) y-l(i)]

>> x=1:10; >> y=2*x+5; >> noise=rand(1,1)*x.^2; >> errorbar(x,y,noise,'ok:') >> xlim([0 11]) >> title('Errorbars')

Pie charts among the less recommend though common use a lot of graphics to represent very low data density Still, if you want to use them it is easily done

pie(x,[outline]): –x is a vector with the value of each data –Outline is a vector of 1s and 0s the same size of x that states which pie slices should be outlined (1) or held together (0)

>> x=[ ] >> outline=x>5; % = [ ] >> pie(x,outline) >> title('Pie chart')