An introduction to Plotting in MATLAB Rikard Johansson Department of Biomedical Engineering (IMT) Linköping University 2015-03-19.

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

Introduction to Engineering MATLAB – 11 Plotting - 4 Agenda Multiple curves Multiple plot.
Plotting Selim Aksoy Bilkent University Department of Computer Engineering
Lecture (4) Plotting & Programming (1) Eng. Osama Talaat 1.
Introduction to Graphing Using MATLAB. Line Graphs  Useful for graphing functions  Useful for displaying data trends over time  Useful for showing.
Matrix Manipulation and 2D Plotting
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.
FIRST COURSE Excel Tutorial 4 Working with Charts and Graphics.
Microsoft Excel 2010 Chapter 7
MATLAB - Lecture 22A Two Dimensional Plots / Chapter 5 Topics Covered:
Using Excel for Data Analysis in CHM 161 Monique Wilhelm.
EGR106 Week 6 MATLAB FILES Two Dimensional Plots Multiple Plots
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.
1 Computing for Todays Lecture 10 Yumei Huo Fall 2006.
Lecture 9 Plotting in 2-D Plotting in 2-D, Plotting Multiple Curves, Plotting with Figures, Plot Settings, Scaling, Legends © 2007 Daniel Valentine. All.
Introduction to Excel 2007 Bar Graphs & Histograms Psych 209 February 1st, 2011.
Using Charts in a Presentation Lesson 6. Software Orientation Charts can help your audience understand relationships among numerical values. The figure.
XP New Perspectives on Microsoft Office Excel 2003 Tutorial 4 1 Microsoft Office Excel 2003 Tutorial 4 – Working With Charts and Graphics.
Introduction to Excel 2007 Part 3: Bar Graphs and Histograms Psych 209.
Graphing with Excel: Graphing Made Easy Mac 2008 Version.
Introduction to Matlab Jianguo Wang CSSCR September 2009.
Instructor: Professor Cora Martinez, PhD Department of Civil and Environmental Engineering Florida International University.
Designing Effective Graphics Using MATLAB The Cain Project in Engineering and Professional Communication ENGINEERING SERIES.
Chapter 5 Review: Plotting Introduction to MATLAB 7 Engineering 161.
Make the Main Title with Large Bold Type Your Name and Title Here Your Department Here Texas A&M Health Science Center Make the Main Title with Large Bold.
Plotting II: By the end of this class you should be able to: Create a properly formatted engineering graph Create graphs of a function Place multiple plots.
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()
„  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.
Microsoft Office Illustrated Introductory, Premium Edition with Charts Working.
A lesson approach © 2011 The McGraw-Hill Companies, Inc. All rights reserved. a lesson approach Microsoft® PowerPoint 2010 © 2011 The McGraw-Hill Companies,
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.
© 2004 by the McGraw-Hill Companies, Inc. All rights reserved. Creating Charts Lecture 19.
Making a Line Graph Open Excel to a new worksheet Type in your team’s information –Normal “resting” heart rate in one row –“Recovery” readings in another.
Advanced Stata Workshop FHSS Research Support Center.
CREATING CHARTS By: Dr. Ennis - Cole OBJECTIVES b Identify the elements of an Excel chart b Identify the type of chart represents your data most effectively.
Session 9 Managerial Spreadsheet Modeling -- Prof. Juran1.
ENG 1181 College of Engineering Engineering Education Innovation Center MATLAB – 2D Plots 1 Go to the class drive: ---> MatLab - Graphing ---> Seed Files.
UW CSE 190p Section 7/26, Summer 2012 Dun-Yu Hsiao.
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,
XP New Perspectives on Microsoft Excel 2002 Tutorial 4 1 Microsoft Excel 2002 Tutorial 4 – Working With Charts and Graphs.
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.
Introduction to Engineering MATLAB – 9 Plotting - 2 Agenda Formatting plots.
Excel Part 4 Working with Charts and Graphics. XP Objectives Create an embedded chart Work with chart titles and legends Create and format a pie chart.
NET 222: COMMUNICATIONS AND NETWORKS FUNDAMENTALS ( NET 222: COMMUNICATIONS AND NETWORKS FUNDAMENTALS (PRACTICAL PART) Lab 2 : potting to Matlab Networks.
CS100A, Fall 1998, Lecture 201 CS100A, Fall 1998 Lecture 20, Tuesday Nov 10 More Matlab Concepts: plotting (cont.) 2-D arrays Control structures: while,
Microsoft Office XP Illustrated Introductory, Enhanced With Charts Working.
Data Representation: Making Tables & Graphs. Data Tables.
Figures & Axes, Printing & Saving. Outline Announcements –Homework I on web, due Wed. 5PM by e- mail A word on HWI and cookies What happens when you plot.
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.
Using Excel graphing functions Mr. Lesser Do Now Compare the two graphs below. Fill out the similarities and differences chart on your paper. Then.
Computer Application in Engineering Design
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
Two-Dimensional Plots
Microsoft PowerPoint 2003 Illustrated Introductory
MATLAB How to use (using M-files) Double click this icon
MATLAB How to use (using M-files) Double click this icon
Plotting Multiple Graphs In The Same Plot
MATLAB How to use (using M-files)
Plotting Signals in MATLAB
Presentation transcript:

An introduction to Plotting in MATLAB Rikard Johansson Department of Biomedical Engineering (IMT) Linköping University CC – isbgroup.eu

You are here!

Outline Part I About plotting in MATLAB – How can you plot – What should you plot – What shouldn’t you plot Basic plotting – Common tools – Customization – Simple editing Part II Customizing your plot using scripts – Linewidth etc. – Axes, labels, legends, titles Part III Customizing your plot using scripts – Handles Part IV Multiple Figures Saving and Exporting Additional Tools

The Examples All examples used in this lecture will have an identification number. You can find the code for these examples on Lisam, along with the slides for this presentation. The examples are divided into cells. Run only the current cell by right-clicking and choosing “Evaluate Current Cell” (shortcut: Ctrl+Enter in windows)

Some things you can do Find more examples at : plot errorbar pie histbarsurf

If you are not presenting data. Use a GUI-friendly program. Powerpoint Adobe illustrator etc. How about this?

The Focus plot The techniques discussed can most often be directly applied to any plotting/chart-type

The plot command >> plot(x,y) This will plot x vs y in the current figure. If there is no current figure, it will create one for you. % Example 1 … y = 4x+30

Plotting multiple things >> hold on To prevent MATLAB from erasing the old plot from figure. Use when you want to plot several (independent) graphs in the same window. % Example 2 … y = 4x+30 y2 = 0 >> hold off To turn it off again

Alternatives sometimes used >> errorbar(x, y, σ) For plotting data with noise >> semilogx(x, y) For having a logarithmic x-axis. >> semilogy(x, y) For having a logarithmic y-axis. >> loglog(x, y) For both axes in log-scale % Example 4 … % Example 5 … % Example 6 … % Example 3 …

Customize your plot >> plot(x, y, s) s is a string controlling: color, marker type, and line type. E.g. s = 'r*-' % Example 7 … y = x 2 Color is red Data points are marked with * The line type is a solid line

Customize your plot >> help plot s = 'r*-'

Choose wisely Think about colors and line types. Are they easy to see? Figures will look different on your computer screen, on a printed A4, on a poster, or in an presentation. % Example 8 … y = x 2 Dashed yellow (s = 'y--') y2 = 4x +30 Dotted cyan (s ='c:')

Edit your plot

An introduction to Plotting in MATLAB Rikard Johansson Department of Biomedical Engineering (IMT) Linköping University CC – isbgroup.eu

Outline Part I About plotting in MATLAB – How can you plot – What should you plot – What shouldn’t you plot Basic plotting – Common tools – Customization – Simple editing Part II Customizing your plot using scripts – Linewidth etc. – Axes, labels, legends, titles Part III Customizing your plot using scripts – Handles Part IV Multiple Figures Saving and Exporting Additional Tools

Edit your plot

Scripted Here’s the latest figure Looks nice but… …please change everything …please change X, Y and Z OK!

Editing in script based environment Saves you time – When you repeatedly want to plot the same (or slightly different figure). E.g. the plot functionality in the cost-function – Want to use the same settings for a new figure (copy it) Allows you to make sweeping changes, like changing the thickness of all lines, with one stroke of the key. Reduces human error (messing things up) Easier for a co-worker to change/modify. Just send them the script!

The Plot Thickens… The 'linewidth' input allows you to plot with any thickness you want. Similarly you can change the size and color etc. of the marker (see the matlab help). % Example 9 … plot(x,y,'r', 'linewidth',5) Note: you can replace the 5 with a variable, and use that variable for all your plots, allowing for easy change of all plots.

Labels/Titles >> xlabel To set a label for the x-axis >> ylabel To set a label for the y-axis >> title To set a title for the plot % Example 10 … xlabel('Time (h)') ylabel('temperature (C)') title('Temperature over a day')

Legends >> legend Use when plotting multiple things in the same window. Name them in the order you plotted them. You can decide where the legend box appears with the 'location' input for legend. >> help legend % Example 11 … legend('July', 'January') % Example 12 … To see an example of the 'location' input

An introduction to Plotting in MATLAB Rikard Johansson Department of Biomedical Engineering (IMT) Linköping University CC – isbgroup.eu

Outline Part I About plotting in MATLAB – How can you plot – What should you plot – What shouldn’t you plot Basic plotting – Common tools – Customization – Simple editing Part II Customizing your plot using scripts – Linewidth etc. – Axes, labels, legends, titles Part III Customizing your plot using scripts – Handles Part IV Multiple Figures Saving and Exporting Additional Tools

Handles A handle is a pointer to another object – A figure – An axis – Something within a figure (label, legend, plot, etc) You can manipulate the object by manipulating the handle. The >>get and >>set commands allows us to read and change the properties of the handles. >> gca Is a MATLAB in-built handle for the current axis. It always exists, you don’t have to define it. >> get(gca)

Handles: Fontsize >> get(gca) By manipulating the gca handle we can change the fontsize used in the figure. >> set(gca, 'fontsize', 15) gca always change for the current/active figure. If you have several figures open, be sure to select the right figure first (click on it). You can alternatively “store” a permanent reference to that handle, e.g.: >> myHandle1 = gca;

Handles: Fontsize % Example 13 … set(gca, 'fontsize', 15) The size of the axis, and the legends changed Not the labels and title. Fix by running the cell again, or ascribe specific handles

Assign your own handles You can assign handles to many things in matlab. Easiest way is to do it when creating them: a = plot(x,y) b = xlabel('time') c = legend('january') d = title('Fantastic Plot') a, b, c, and d are all handles. You can manipulate them using the >> get and >> set commands

Can you handle it? In the example below a separate handle is created for each object we want to change the fontsize for. The >> set(handle, 'fontsize', newValue) takes care of the rest % Example 14 … One fontsize for the axes. A second for the labels, title, and legend.

Other uses of handles Changing range of the axis (the limits) Setting where the “ticks” are. Changing the names of the ticks. Change between log-scale and normal scale. % Example 15 … Xlim to [10 15] Ylim to [0 30]

An introduction to Plotting in MATLAB Rikard Johansson Department of Biomedical Engineering (IMT) Linköping University CC – isbgroup.eu

Outline Part I About plotting in MATLAB – How can you plot – What should you plot – What shouldn’t you plot Basic plotting – Common tools – Customization – Simple editing Part II Customizing your plot using scripts – Linewidth etc. – Axes, labels, legends, titles Part III Customizing your plot using scripts – Handles Part IV Multiple Figures Saving and Exporting Additional Tools

Multiple figures >> figure() Will open a new, empty, plot. >> figure(X) Will navigate to the Xth plot, or create it if it doesn’t exist. The examples used herein, uses this. Sometimes you wish to make an array (a matrix) of figures. This is accomplished using the >> subplot command. >> subplot(y, x, number) RowsColumns Element #

Subplot A 2 x 2 subplot array % Example 16 …

Choose your own color Find a color you like. Look for instance here: Get the RGB values Change to values between 0 and 1 by dividing with 255. Use the 'color' property in plot % Example 17 …

Additional tools >> line Draws lines in your plot. >> rectangle To draw rectangles (and circles) >> fill To draw any polygon you want. >> text To write text in your figure % Example 18 …

Saving your pictures The easiest way Or, if you wish to do it script style Use the >> print command. >> help print Will tell you how to save to a particular file format, and to increase the resolution (dpi)

Remember Check that your plots will be easy to read Use the MATLAB help to learn more about the functionalities. Google it! Someone else probably had the same problem. Ask on Lisam!

Questions/Comments?