Basic plotting commands Types of plots Customizing plots graphically Specifying color Customizing plots programmatically Exporting figures

Similar documents
PROGRAMMING WITH MATLAB WEEK 6

Mechanical Engineering Department Second Year (2015)

W1005 Intro to CS and Programming in MATLAB. Plo9ng & Visualiza?on. Fall 2014 Instructor: Ilia Vovsha. hgp://

STAT 391 Handout 1 Making Plots with Matlab Mar 26, 2006

Logical Subscripting: This kind of subscripting can be done in one step by specifying the logical operation as the subscripting expression.

SGN Introduction to Matlab

Basic Graphs. Dmitry Adamskiy 16 November 2011

CSE 123. Plots in MATLAB

fplot Syntax Description Examples Plot Symbolic Expression Plot symbolic expression or function fplot(f) fplot(f,[xmin xmax])

INC151 Electrical Engineering Software Practice. MATLAB Graphics. Dr.Wanchak Lenwari :Control System and Instrumentation Engineering, KMUTT 1

Matlab Tutorial 1: Working with variables, arrays, and plotting

GUI Alternatives. Syntax. Description. MATLAB Function Reference plot. 2-D line plot

12 whereas if I terminate the expression with a semicolon, the printed output is suppressed.

NENS 230 Assignment 4: Data Visualization

MATLAB Laboratory 09/23/10 Lecture. Chapters 5 and 9: Plotting

Department of Chemical Engineering ChE-101: Approaches to Chemical Engineering Problem Solving MATLAB Tutorial Vb

This module aims to introduce Precalculus high school students to the basic capabilities of Matlab by using functions. Matlab will be used in

Dr Richard Greenaway

More on Plots. Dmitry Adamskiy 30 Nov 2011

Introduction to MATLAB: Graphics

MATH 2221A Mathematics Laboratory II

Dr. Iyad Jafar. Adapted from the publisher slides

Graphics and plotting techniques

PART 1 PROGRAMMING WITH MATHLAB

Introduction to MATLAB

EOSC 473/573 Matlab Tutorial R. Pawlowicz with changes by M. Halverson

INTRODUCTION TO MATLAB PLOTTING WITH MATLAB

What is Matlab? A software environment for interactive numerical computations

AMS 27L LAB #2 Winter 2009

Getting Started. Chapter 1. How to Get Matlab. 1.1 Before We Begin Matlab to Accompany Lay s Linear Algebra Text

Basic MATLAB Intro III

The Department of Engineering Science The University of Auckland Welcome to ENGGEN 131 Engineering Computation and Software Development

Graphics in MATLAB. Responsible teacher: Anatoliy Malyarenko. November 10, Abstract. Basic Plotting Commands

APPM 2460 PLOTTING IN MATLAB

Basic Beginners Introduction to plotting in Python

Graphics Example a final product:

INTERNATIONAL EDITION. MATLAB for Engineers. Third Edition. Holly Moore

MATLAB Introduction to MATLAB Programming

Introduction to Matlab to Accompany Linear Algebra. Douglas Hundley Department of Mathematics and Statistics Whitman College

DATA PLOTTING WITH MATLAB

2D LINE PLOTS... 1 The plot() Command... 1 Labeling and Annotating Figures... 5 The subplot() Command... 7 The polarplot() Command...

Introduction to Matlab. WIAA Technical Workshop #2 10/20/2015

A MATLAB Exercise Book. Ludmila I. Kuncheva and Cameron C. Gray

1. Register an account on: using your Oxford address

PyPlot. The plotting library must be imported, and we will assume in these examples an import statement similar to those for numpy and math as

Chapter 3: Introduction to MATLAB Programming (4 th ed.)

Overview. Lecture 13: Graphics and Visualisation. Graphics & Visualisation 2D plotting. Graphics and visualisation of data in Matlab

EGR 102 Introduction to Engineering Modeling. Lab 05B Plotting

MATLAB Modul 2. Introduction to Computational Science: Modeling and Simulation for the Sciences, 2 nd Edition

1 >> Lecture 4 2 >> 3 >> -- Graphics 4 >> Zheng-Liang Lu 184 / 243

Introduction to MATLAB

Appendix A. Introduction to MATLAB. A.1 What Is MATLAB?

QUICK INTRODUCTION TO MATLAB PART I

MATLAB SUMMARY FOR MATH2070/2970

PyPlot. The plotting library must be imported, and we will assume in these examples an import statement similar to those for numpy and math as

Classes 7-8 (4 hours). Graphics in Matlab.

Part #6. A0B17MTB Matlab. Miloslav Čapek Filip Kozák, Viktor Adler, Pavel Valtr

Additional Plot Types and Plot Formatting

1 Introduction to Matlab

MATH36032 Problem Solving by Computer. Publishable Quality Graphics

Introduction to Programming in MATLAB

Data Analysis in Geophysics ESCI Class 17. Bob Smalley. More Matlab.

Prof. Manoochehr Shirzaei. RaTlab.asu.edu

FF505/FY505 Computational Science. MATLAB Graphics. Marco Chiarandini

Interactive Computing with Matlab. Gerald W. Recktenwald Department of Mechanical Engineering Portland State University

Name: INSERT YOUR NAME HERE UWNetID: INSERT YOUR NETID

MATLAB Tutorial. 1. The MATLAB Windows. 2. The Command Windows. 3. Simple scalar or number operations

MATLAB Functions and Graphics

Computing Fundamentals Plotting

TikZ & PGF(plots) Daniel Knittl-Frank. May This work is licensed under the Creative Commons Attribution-ShareAlike 3.

What is MATLAB? It is a high-level programming language. for numerical computations for symbolic computations for scientific visualizations

Chapter 2. MATLAB Fundamentals

Introduction to Matlab

CCNY. BME 2200: BME Biostatistics and Research Methods. Lecture 4: Graphing data with MATLAB

Plotting - Practice session

ENGR Fall Exam 1

Introduction to Matlab

Introduction to MATLAB programming: Fundamentals

Lab 5: Matlab Tutorial Due Sunday, May 8 at midnight

MATLAB Fundamentals. Berlin Chen Department of Computer Science & Information Engineering National Taiwan Normal University

MATLAB Tutorial III Variables, Files, Advanced Plotting

3D plot of a surface in Matlab

Miami Conservancy District Logo Specs

Name: Math Analytic Geometry and Calculus III - Spring Matlab Project - due on Wednesday, March 30

Advanced Programming in MATLAB

The MathWorks - MATLAB Digest June Exporting Figures for Publication

Hello Earth! A grounded introduction to Matlab. Frederik J Simons. Christopher Harig. Adam C. Maloof Princeton University

Matlab Concise Notes

PSY8219 : Week 6. Homework 5 Due Today. Homework 6 Due October 8. Readings for Today Attaway Chapter 6, 10, and 12

MAT 275 Laboratory 1 Introduction to MATLAB

Introduction to MATLAB

Beyond the Mouse A Short Course on Programming

Computer Programming in MATLAB

What is MATLAB? What is MATLAB? Programming Environment MATLAB PROGRAMMING. Stands for MATrix LABoratory. A programming environment

Scientific Python: matplotlib

Introduction to Scientific Programming in MATLAB

ENGG1811 Computing for Engineers Week 11 Part C Matlab: 2D and 3D plots

PowerPoints organized by Dr. Michael R. Gustafson II, Duke University

Introduction to MATLAB LAB 1

Introduction to Matlab

Transcription:

Basic plotting commands Types of plots Customizing plots graphically Specifying color Customizing plots programmatically Exporting figures

Matlab is flexible enough to let you quickly visualize data, and powerful enough to give you complete control over the final product Features: Interactive plotting simple 3D plotting programmatic annotation

2D Visualization plot (line plots) histogram scatter (scatter plots) image/imagesc (images) 3D Visualization surf/mesh (surfaces) plot3 (lines) scatter3

Create a new figure : figure(); Specify a figure number: figure(1) Hold onto a figure handle fighandle1 = figure(1); Re-select a figure: figure(fighandle1) Some useful functions: clf: close all: gcf: clear figure closes all figures get handle to current figure

Syntax: plot(x,y) plots points in the vector y against points in the vector x

Syntax: histogram(y) plots a histogram of the values in y, bar(x,y) plots bars at the points given by (x,y)

Syntax: scatter(x,y,s,c) lets you specify the size (s) and color (c) of each point given by (x,y)

Syntax: image(c) plots the values stored in the matrix C as an image

Syntax: surf(x,y,z) and mesh(x,y,z) are used to visualize a surface in three dimensions

Syntax: plot3(x,y,z) plot points in 3D

http://www.mathworks.com/help/matlab/2-and-3d-plots.html

the subplot command let s you plot multiple plots on one figure syntax: subplot(nrows, ncols, index) (Figure 1) subplot(1,3,1) subplot(1,3,2) subplot(1,3,3)

the subplot command let s you plot multiple plots on one figure syntax: subplot(nrows, ncols, index) (Figure 2) subplot(3,2,1) subplot(3,2,2) subplot(3,2,3) subplot(3,2,4) subplot(3,2,5) subplot(3,2,6)

gca panel get handle to current axis

Panel() user-submitted function from Matlab File Exchange (FEX) http://www.mathworks.com/matlabcentral/fileexchange/20003-panel Provides MUCH more control over subplot positioning, layout, margins, etc.

Plot() plots along dimension 1 of an array. If there are multiple dimensions, plot creates a separate line for each column If your data isn t constructed this way, just transpose with the apostrophy character: plot(data )

For line plots, specify the line type using a format string: plot(x,y, b ) % plots blue line (default) plot(x,y, b. ) % plots blue dots plot(x,y, b: ) % plots blue dotted line plot(x,y, k-- ) % plots black dashed line plot(x,y, ro ) % plots red circles Chain together characters for full specification of color, marker, and line plot(x,y, ro- ) % plots red circles with solid line plot(x,y, ro: ) % plots red circles with dotted line

For line plots, specify the line type using a format string: plot(x,y, b ) % plots blue line (default) plot(x,y, b. ) % plots blue dots plot(x,y, b: ) % plots blue dotted line plot(x,y, k-- ) % plots black dashed line plot(x,y, ro ) % plots red circles Chain together characters for full specification of color, marker, and line plot(x,y, ro- ) % plots red circles with solid line plot(x,y, ro: ) % plots red circles with dotted line

Everything you can do graphically you can also do programmatically. DON T do something by hand if you have to do it more than once! Examples axes labels: xlabel( text ), ylabel( text ) plot/axis title: title( text ) Add text: text(x,y, text to add )

Graphics parameters are usually specified as parameter, value pairs: plot(x,y, linewidth, 1.4) plot(x,y, bo-, linewidth, 2, markersize, 15) plot(x,y, o-, MarkerFaceColor, [1 0 0], markeredgecolor, [0 0 1])

grid on axis off colorbar colormap hot adds grid lines turns off the axes adds a colorbar to image plot switch colormap

Matlab has 8 built-in colors: Black (k), Red (r), Blue (b), Green (g), Cyan (c), Magenta (m), Yellow (y), White (w) We can specify other colors using RGB (red, green blue) notation: red = [1 0 0] blue = [0 0 1] green = [0 1 0] gray = [0.2 0.2 0.2] black = [0 0 0] All RGB colors are 1x3 arrays and all elements between 0-1.

Colormaps are used to specify how data gets mapped onto different colors. Matlab has a few built-in colormaps, but you can also specify your own!

Figures in Matlab are referenced using handles, which are pointers to different parts of the figure. Example: myhandle = plot(x,y); Will return a handle to the plot. Then you can run the following: get(myhandle); % to see a list of properties set(myhandle, Name,Value); % to set the value of a property

Different parts of the figure are organized hierarchically: >> gcf >> gca >> get(gca,'children') >> get(gcf,'children')

Matlab saves figures using it s own.fig format. To share figures or view outside matlab, export to other formats, including: JPG, PNG, EPS, PDF, TIFF

Two main classes of image formats: bitmap vs. vector graphics Bitmap (jpg, png): Fixed image sizes Best for actual images (pictures of stuff) Vector (eps, pdf): Variable image sizes Best for line / bar graphs, scatter plots, etc.

print(fighandle,filename,formattype) e.g.: print(figure(1), MyPlot, -dpng ) formats: -dpng, -depsc2, -dpdf, etc add flag for resolution: -r300, etc

2D and 3D visualization examples: http://www.mathworks.com/help/matlab/2-and-3d-plots.html Custom colormaps: http://colorbrewer.org Panel http://www.mathworks.com/matlabcentral/fileexchange/20003- panel Colors in figures (blog post) http://figuredesign.blogspot.com/2012/04/meeting-recap-colorsin-figures.html

Cawley et. al., Cell, Volume 116, Issue 4, 20 February 2004.

100% 75% Proportion 50% 25% 0% <30 30- <33 33- <36 36- <39 >=39 All Hematocrit Group(%) <=8,738 units/wk >8,738-13,944 units/wk >13,944-21,692 units/wk >21,692 units/wk Cotter et. al., Journal of Clinical Epidemiology 57 (2004)