PYTHON PLOTTING CURVES CHAPTER 10_5 FROM THINK PYTHON HOW TO THINK LIKE A COMPUTER SCIENTIST.

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

Computation for Physics 計算物理概論
Introduction to Engineering MATLAB – 11 Plotting - 4 Agenda Multiple curves Multiple plot.
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.
1 Chapter 4 Curve Plotting with MATLAB MATLAB provides some very powerful features for plotting and labeling curves. These operations can be performed.
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.
DAY 8: MICROSOFT EXCEL – CHAPTER 5 Aliya Farheen February 5, 2015.
Lab5 (Signal & System) Instructor: Anan Osothsilp Date: 20 Feb 07 Due Date 09 March 07.
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.
 Monday, 9/30/02, Slide #1 CS106 Introduction to CS1 Monday, 9/30/02  QUESTIONS (on HW02, etc.)??  Today: Libraries, program design  More on Functions!
EGR106 Week 6 MATLAB FILES Two Dimensional Plots Multiple Plots
1 Committed to Shaping the Next Generation of IT Experts. Chapter 3 – Graphs and Charts: Delivering a Message Robert Grauer and Maryann Barber Exploring.
1 Introduction to MatLab MatLab stands for Matrix Laboratory. As the name suggests most of the programming operations have as input or output a matrix.
EGR106 Week 4 Two Dimensional Plots Multiple Plots Plot Formatting Homework.
Introduction to MATLAB MECH 300H Spring Starting of MATLAB.
SPSS Statistical Package for the Social Sciences is a statistical analysis and data management software package. SPSS can take data from almost any type.
Python plotting for lab folk Only the stuff you need to know to make publishable figures of your data. For all else: ask Sourish.
Introduction to Matlab Jianguo Wang CSSCR September 2009.
An introduction to Plotting in MATLAB Rikard Johansson Department of Biomedical Engineering (IMT) Linköping University
IMAGE PROCESSING LIBRARY (PIL) This is a package that you can import into python and it has quite a few methods that you can process image files with.
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()
PYTHON EEG ANALYSIS EXAMPLE FROM THINK PYTHON HOW TO THINK LIKE A COMPUTER SCIENTIST.
„  1999 BG Mobasseri1 9/18/2015 June 2 GRAPHICS IN MATLAB- PART I BASIC PLOTTING.
Matlab tutorial course Lesson 5: Loading and writing data, producing visual output
418512: Computer Programming Languages Lecture 7 Pramook Khungurn TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.: A AAAA.
MATLAB Tutorial EE 327 Signals and Systems 1. What is MATLAB? MATLAB – Matrix Laboratory The premier number-crunching software Extremely useful for signal.
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.
Post-Processing Output with MATLAB Claudia Fricke Institute of Petroleum Engineering, Heriot Watt University.
Recap Sum and Product Functions Matrix Size Function Variance and Standard Deviation Random Numbers Complex Numbers.
Introduction to Programming Workshop 6 PHYS1101 Discovery Skills in Physics Dr. Nigel Dipper Room 125d
Chapter 1 – Matlab Overview EGR1302. Desktop Command window Current Directory window Command History window Tabs to toggle between Current Directory &
Matlab Screen  Command Window  type commands  Current Directory  View folders and m-files  Workspace  View program variables  Double click on a.
UW CSE 190p Section 7/26, Summer 2012 Dun-Yu Hsiao.
EGR 106 Lecture 6 2-D Plotting Graphical presentation has become the standard method to show technical information. Engineers use plots to analyze, visualize,
Python Crash Course Numpy & MatplotLib Sterrenkundig Practicum 2 V1.0 dd Hour 3.
Excel Graphing ENGR 1181 Class 5. Why use Excel?  Excel is a powerful spreadsheet program that can be used for: Creating graphical displays of data Performing.
1 Lecture 5 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept.
Matplotlib SANTHOSH Boggarapu.
1 CSE 2337 Chapter 7 Organizing Data. 2 Overview Import unstructured data Concatenation Parse Create Excel Lists.
Introduction to plotting data Fish 552: Lecture 4.
1 Berger Jean-Baptiste
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.
Numerical and Scientific Computing Part 2
Lecture 25.
Project 1 Part E3 Programming PicoScope ---Looping--
IPYTHON AND MATPLOTLIB Python for computational science
Lecture 25: Exploring data
Two-Dimensional Plots
Visualization UW CSE 160 Spring 2018.
Reading a CSV file in R.
MATLAB How to use (using M-files) Double click this icon
MATLAB Tutorial Dr. David W. Graham.
MATLAB How to use (using M-files) Double click this icon
Python plotting curves chapter 10_5
Plotting Multiple Graphs In The Same Plot
Matplotlib.
MATLAB How to use (using M-files)
funCTIONs and Data Import/Export
Notes on pyplot Professor Hugh C. Lauer CS-1004 — Introduction to Programming for Non-Majors (Slides include materials from Python Programming: An Introduction.
CSV files Professor Hugh C. Lauer CS-1004 — Introduction to Programming for Non-Majors (Slides include materials from Python Programming: An Introduction.
Plotting Signals in MATLAB
Matplotlib and Pandas
Programming with data Lab 3
Presentation transcript:

PYTHON PLOTTING CURVES CHAPTER 10_5 FROM THINK PYTHON HOW TO THINK LIKE A COMPUTER SCIENTIST

MATPLOTLIB matplotlib.pyplotmatplotlib.pyplot is a collection of command style functions that make matplotlib work like MATLAB. Each pyplot function makes some change to a figure: eg, create a figure, create a plotting area in a figure, plot some lines in a plotting area, decorate the plot with labels, etc.... import matplotlib.pyplot as plt plt.plot([1,2,3,4]) plt.ylabel('some numbers') plt.show() from matplotlib.pyplot import * plot([1,2,3,4]) ylabel('some numbers') show() Auto generates x values here!

PLOT plot()plot() is a versatile command, and will take an arbitrary number of arguments. For example, to plot x versus y, you can issue the command: plt.plot([1,2,3,4], [1,4,9,16]) For every x, y pair of arguments, there is an optional third argument which is the format string that indicates the color and line type of the plot. import matplotlib.pyplot as plt plt.plot([1,2,3,4], [1,4,9,16], 'ro') plt.axis([0, 6, 0, 20]) plt.show() red circle

LINE AND TEXT PROPERTIES import matplotlib.pyplot as plt plt.plot([1,2,3,4], [1,4,9,16], linewidth=8.0 ) #thick line plt.axis([0, 6, 0, 20]) #sets y axis values plt.xlabel('This is the x axis', fontsize=14,color = 'red') plt.ylabel('This is the y axis') plt.title('Our Example Graph') plt.show() Text Properties 2d Line Properties

TWO GRAPHS import matplotlib.pyplot as plt # plot graphs plt.plot([1,2,3,4,5], [1,4,9,16,25], linewidth = 4.0, color='blue') #thick line plt.plot([1,2,3,4,5],[1,2,3,4,5], linewidth = 4.0, color='red') plt.axis([0, 6, 0, 30]) #sets y axis values plt.xlabel('This is the x axis', fontsize = 14, color = 'green') plt.ylabel('This is the y axis', fontsize = 14, color = 'green') plt.title('Our Example with two Graphs', fontsize = 18, color = 'blue') plt.show()

CSV FILES Comma separated value Comma separated value files are very popular and it turns out that python can easily process these guys. These are quite simple involving nothing more than data separated by commas. Normally each line of a csv file has the same number of values listed. Spaces are allowed. 12, 34, 54, 6, 5 5,43,77,2,33 78,12,8,4, 23 and so on. We normally read each line of the file and split it up using the commas as an indication where to separate the values.

EXAMPLE USING SPLIT Suppose the past slides data is in file data.txt. The following program will read in each line and print it out separated by spaces (just to show it works) file = open('data.txt','r') for line in file: nums = line.split(',') # nums is now a list of the values for v in nums: print v, OUTPUT:

CSV FILES AND EXCEL Excel knows about CSV files if.csv is used as the extension Suppose we create a csv file using python. x=-10 x_values=[] file=open('data.csv','w') while(x<=10): x_values.append(x) x=x+.5 for x in x_values: print >>file,x,’,’, x**2,',',10*x file.close() You can open data.csv in excel now the csv extension is required

SAME THING IN PYTHON import matplotlib.pyplot as plt x=-10 x_values=[] file=open('data.csv','w') while(x<=10): x_values.append(x) x=x+.5 y1_value=[] y2_value=[] for x in x_values: y1_value.append(x**2) y2_value.append(10*x) plt.plot(x_values,y1_value) plt.plot(x_values,y2_value) plt.show() file.close()

READING EEG DATA First lets look at eegdata as generated by a 14 channel emotive headset. This device creates a csv file that has quite a few values per row. We are only interested in the first 16 values. You can look at the.csv file using either excel or a pure text editor or both. Excel will automatically load the.csv file into columns using the, as a separator. headset Let do so in class today.

HERE IS THE CODE TO READ ONE COLUMN ONLY AND GRAPH. from pylab import plot, show, title, xlabel, figure def readData(fp,col): values=[] fp.readline() #skip the first line for line in fp: #extract column col. Col 2 is the first real one row=line.split(",") values.append( float(row[col])) return values

CONTINUED filename='eegdata.csv' fp = open(filename) ch = raw_input('Enter channel you want to display') ch = int(ch) fig=figure(1) fig.suptitle("EEG Channel Display\n",fontsize=24) y_values=[] fp.readline() #skip the first line for line in fp: #extract column col. Col 2 is the first real one row=line.split(",") y_values.append( float(row[ch])) title('Channel '+str(ch)) xlabel('Time(1/128 of a sec)') plot(y_values[0:1100]) show()