SlideShare une entreprise Scribd logo
1  sur  34
Télécharger pour lire hors ligne
Python for Science and Engg:
           Interactive Plotting

                                FOSSEE
                      Department of Aerospace Engineering
                                  IIT Bombay


                        12 February, 2010
                         Day 1, Session 1


FOSSEE (IIT Bombay)              Interactive Plotting       1 / 34
Workshop Schedule: Day 1



Session 1 Fri 14:00–15:00
Session 2 Fri 15:05–16:05
Session 3 Fri 16:10–17:10
  Quiz 1 Fri 17:10–17:25
Exercises Thu 17:30–18:00




  FOSSEE (IIT Bombay)   Interactive Plotting   2 / 34
Workshop Schedule: Day 2



Session 1 Sat 09:00–10:00
Session 2 Sat 10:05–11:05
Session 3 Sat 11:20–12:20
  Quiz 2 Fri 14:25–14:40




  FOSSEE (IIT Bombay)   Interactive Plotting   3 / 34
Workshop Schedule: Day 3



Session 1 Sun 09:00–10:00
Session 2 Sun 10:05–11:05
Session 3 Sun 11:20–12:20
  Quiz 3 Sun 12:20–12:30
Exercises Sun 12:30–13:00




  FOSSEE (IIT Bombay)   Interactive Plotting   4 / 34
Checklist


Outline

1   Checklist
2   Starting up Ipython
3   Loops
4   Plotting
       Drawing plots
       Decoration
       More decoration
5   Multiple plots

    FOSSEE (IIT Bombay)     Interactive Plotting   5 / 34
Checklist


Checklist
 1
        IPython
 2
        Editor
 3
        Data files:
                 sslc1.txt
                 pendulum.txt
                 points.txt
                 pos.txt
                 holmes.txt
 4
        Python scripts:
                 sslc_allreg.py
                 sslc_science.py
 5
        Images
                 lena.png
                 smoothing.gif
     FOSSEE (IIT Bombay)        Interactive Plotting   6 / 34
Checklist


About the Workshop

Intended Audience
     Engg., Mathematics and Science teachers.
     Interested students from similar streams.

Goal: Successful participants will be able to
    Use Python as plotting, computational tool.
    Understand how to use Python as a scripting and
    problem solving language.
    Train students for the same.


  FOSSEE (IIT Bombay)     Interactive Plotting        7 / 34
Starting up Ipython


Outline

1   Checklist
2   Starting up Ipython
3   Loops
4   Plotting
       Drawing plots
       Decoration
       More decoration
5   Multiple plots

    FOSSEE (IIT Bombay)               Interactive Plotting   8 / 34
Starting up Ipython


Starting up . . .


  $ ipython -pylab

  In []: print "Hello, World!"
  Hello, World!
Exiting
  In []: ^D(Ctrl-D)
  Do you really want to exit([y]/n)? y


  FOSSEE (IIT Bombay)               Interactive Plotting   9 / 34
Loops


Outline

1   Checklist
2   Starting up Ipython
3   Loops
4   Plotting
       Drawing plots
       Decoration
       More decoration
5   Multiple plots

    FOSSEE (IIT Bombay)   Interactive Plotting   10 / 34
Loops


Loops

Breaking out of loops
  In []: while True:
    ...:     print "Hello, World!"
    ...:
  Hello, World!
  Hello, World!^C(Ctrl-C)
  ------------------------------------
  KeyboardInterrupt



  FOSSEE (IIT Bombay)   Interactive Plotting   11 / 34
Plotting


Outline

1   Checklist
2   Starting up Ipython
3   Loops
4   Plotting
       Drawing plots
       Decoration
       More decoration
5   Multiple plots

    FOSSEE (IIT Bombay)   Interactive Plotting   12 / 34
Plotting    Drawing plots


Outline

1   Checklist
2   Starting up Ipython
3   Loops
4   Plotting
       Drawing plots
       Decoration
       More decoration
5   Multiple plots

    FOSSEE (IIT Bombay)   Interactive Plotting        13 / 34
Plotting    Drawing plots


First Plot




                        In []: x = linspace(0, 2*pi, 50)
                        In []: plot(x, sin(x))




  FOSSEE (IIT Bombay)            Interactive Plotting        14 / 34
Plotting    Drawing plots


Walkthrough

x = linspace(start, stop, num)
returns num evenly spaced points, in the interval
[start, stop].

x[0] = start
x[num - 1] = end


plot(x, y)
plots x and y using default line style and color

  FOSSEE (IIT Bombay)   Interactive Plotting        15 / 34
Plotting    Decoration


Outline

1   Checklist
2   Starting up Ipython
3   Loops
4   Plotting
       Drawing plots
       Decoration
       More decoration
5   Multiple plots

    FOSSEE (IIT Bombay)   Interactive Plotting     16 / 34
Plotting    Decoration


Adding Labels




                       In []: xlabel(’x’)

                       In []: ylabel(’sin(x)’)




 FOSSEE (IIT Bombay)    Interactive Plotting     17 / 34
Plotting    Decoration


Another example


In []: clf()
Clears the plot area.

In   []:       y = linspace(0, 2*pi, 50)
In   []:       plot(y, sin(2*y))
In   []:       xlabel(’y’)
In   []:       ylabel(’sin(2y)’)



  FOSSEE (IIT Bombay)   Interactive Plotting     18 / 34
Plotting    More decoration


Outline

1   Checklist
2   Starting up Ipython
3   Loops
4   Plotting
       Drawing plots
       Decoration
       More decoration
5   Multiple plots

    FOSSEE (IIT Bombay)   Interactive Plotting          19 / 34
Plotting    More decoration


Title and Legends
In []: title(’Sinusoids’)
In []: legend([’sin(2y)’])




 FOSSEE (IIT Bombay)   Interactive Plotting          20 / 34
Plotting    More decoration


Legend Placement

In []: legend([’sin(2y)’], loc = ’center’)




                                               ’best’
                                               ’right’
                                               ’center’




  FOSSEE (IIT Bombay)   Interactive Plotting              21 / 34
Plotting    More decoration


Saving & Closing



In []: savefig(’sin.png’)

In []: close()




 FOSSEE (IIT Bombay)   Interactive Plotting          22 / 34
Multiple plots


Outline

1   Checklist
2   Starting up Ipython
3   Loops
4   Plotting
       Drawing plots
       Decoration
       More decoration
5   Multiple plots

    FOSSEE (IIT Bombay)         Interactive Plotting   23 / 34
Multiple plots


Overlaid Plots


In   []:       clf()
In   []:       plot(y, sin(y))
In   []:       plot(y, cos(y))
In   []:       xlabel(’y’)
In   []:       ylabel(’f(y)’)
In   []:       legend([’sin(y)’, ’cos(y)’])
By default plots would be overlaid!



  FOSSEE (IIT Bombay)         Interactive Plotting   24 / 34
Multiple plots


Plotting separate figures

In   []:      clf()
In   []:      figure(1)
In   []:      plot(y, sin(y))
In   []:      figure(2)
In   []:      plot(y, cos(y))
In   []:      savefig(’cosine.png’)
In   []:      figure(1)
In   []:      title(’sin(y)’)
In   []:      savefig(’sine.png’)
In   []:      close()
In   []:      close()

 FOSSEE (IIT Bombay)         Interactive Plotting   25 / 34
Multiple plots


Showing it better
In []: plot(y, cos(y), ’r’)

In []: clf()
In []: plot(y, sin(y), ’g’, linewidth=2)




 FOSSEE (IIT Bombay)         Interactive Plotting   26 / 34
Multiple plots


Annotating
In []: annotate(’local max’, xy=(1.5, 1))




 FOSSEE (IIT Bombay)         Interactive Plotting   27 / 34
Multiple plots


Axes lengths


Get the axes limits
In []: xmin, xmax = xlim()
In []: ymin, ymax = ylim()
Set the axes limits
In []: xlim(xmin, 2*pi)
In []: ylim(ymin-0.2, ymax+0.2)



  FOSSEE (IIT Bombay)         Interactive Plotting   28 / 34
Multiple plots


Review Problem
 1
        Plot x, -x, sin(x), xsin(x) in range −5π to 5π
 2
        Add a legend
 3
        Annotate the origin
 4
        Set axes limits to the range of x




     FOSSEE (IIT Bombay)         Interactive Plotting    29 / 34
Multiple plots


Review Problem . . .

Plotting . . .
In    []:        x=linspace(-5*pi, 5*pi, 500)
In    []:        plot(x, x, ’b’)
In    []:        plot(x, -x, ’b’)
In    []:        plot(x, sin(x), ’g’, linewidth=2)
In    []:        plot(x, x*sin(x), ’r’,
                      linewidth=3)
.
.
.


    FOSSEE (IIT Bombay)         Interactive Plotting   30 / 34
Multiple plots


Review Problem . . .

Legend & Annotation. . .
In []: legend([’x’, ’-x’, ’sin(x)’,
               ’xsin(x)’])
In []: annotate(’origin’, xy = (0, 0))
Setting Axes limits. . .
In []: xlim(-5*pi, 5*pi)
In []: ylim(-5*pi, 5*pi)



   FOSSEE (IIT Bombay)           Interactive Plotting   31 / 34
Multiple plots


Saving Commands

Save commands of review problem into file
    Use %hist command of IPython
    Identify the required line numbers
    Then, use %save command of IPython
In []: %hist
In []: %save four_plot.py 16 18-27
Careful about errors!
%hist will contain the errors as well,
so be careful while selecting line numbers.


  FOSSEE (IIT Bombay)         Interactive Plotting   32 / 34
Multiple plots


Python Scripts. . .



This is called a Python Script.
     run the script in IPython using
     %run -i four_plot.py




  FOSSEE (IIT Bombay)         Interactive Plotting   33 / 34
Multiple plots


What did we learn?

    Starting up IPython
    %hist - History of commands
    %save - Saving commands
    Running a script using %run -i
    Creating simple plots.
    Adding labels and legends.
    Annotating plots.
    Changing the looks: size, linewidth


 FOSSEE (IIT Bombay)         Interactive Plotting   34 / 34

Contenu connexe

Tendances

Introduction to Iteratees (Scala)
Introduction to Iteratees (Scala)Introduction to Iteratees (Scala)
Introduction to Iteratees (Scala)Alexander Lehmann
 
Introduction to NumPy (PyData SV 2013)
Introduction to NumPy (PyData SV 2013)Introduction to NumPy (PyData SV 2013)
Introduction to NumPy (PyData SV 2013)PyData
 
Introduction to Gura Programming Language
Introduction to Gura Programming LanguageIntroduction to Gura Programming Language
Introduction to Gura Programming LanguageYutaka Saito
 
Introduction to matplotlib
Introduction to matplotlibIntroduction to matplotlib
Introduction to matplotlibPiyush rai
 
Закон Деметры / Demetra's law
Закон Деметры / Demetra's lawЗакон Деметры / Demetra's law
Закон Деметры / Demetra's lawAlexander Granin
 
Intoduction to numpy
Intoduction to numpyIntoduction to numpy
Intoduction to numpyFaraz Ahmed
 
A peek on numerical programming in perl and python e christopher dyken 2005
A peek on numerical programming in perl and python  e christopher dyken  2005A peek on numerical programming in perl and python  e christopher dyken  2005
A peek on numerical programming in perl and python e christopher dyken 2005Jules Krdenas
 
Tensor board
Tensor boardTensor board
Tensor boardSung Kim
 
C Programming: Pointer (Examples)
C Programming: Pointer (Examples)C Programming: Pointer (Examples)
C Programming: Pointer (Examples)Joongheon Kim
 
Deep learning for Junior Developer
Deep learning for Junior DeveloperDeep learning for Junior Developer
Deep learning for Junior DeveloperCrazia Wolfgang
 
[DevDay2019] Python Machine Learning with Jupyter Notebook - By Nguyen Huu Th...
[DevDay2019] Python Machine Learning with Jupyter Notebook - By Nguyen Huu Th...[DevDay2019] Python Machine Learning with Jupyter Notebook - By Nguyen Huu Th...
[DevDay2019] Python Machine Learning with Jupyter Notebook - By Nguyen Huu Th...DevDay.org
 
Python for Scientific Computing -- Ricardo Cruz
Python for Scientific Computing -- Ricardo CruzPython for Scientific Computing -- Ricardo Cruz
Python for Scientific Computing -- Ricardo Cruzrpmcruz
 
Shape Safety in Tensor Programming is Easy for a Theorem Prover -SBTB 2021
Shape Safety in Tensor Programming is Easy for a Theorem Prover -SBTB 2021Shape Safety in Tensor Programming is Easy for a Theorem Prover -SBTB 2021
Shape Safety in Tensor Programming is Easy for a Theorem Prover -SBTB 2021Peng Cheng
 
Finding root of equation (numarical method)
Finding root of equation (numarical method)Finding root of equation (numarical method)
Finding root of equation (numarical method)Rajan Thakkar
 
Breadth first search signed
Breadth first search signedBreadth first search signed
Breadth first search signedAfshanKhan51
 
Pythonbrasil - 2018 - Acelerando Soluções com GPU
Pythonbrasil - 2018 - Acelerando Soluções com GPUPythonbrasil - 2018 - Acelerando Soluções com GPU
Pythonbrasil - 2018 - Acelerando Soluções com GPUPaulo Sergio Lemes Queiroz
 

Tendances (19)

Introduction to Iteratees (Scala)
Introduction to Iteratees (Scala)Introduction to Iteratees (Scala)
Introduction to Iteratees (Scala)
 
Introduction to NumPy (PyData SV 2013)
Introduction to NumPy (PyData SV 2013)Introduction to NumPy (PyData SV 2013)
Introduction to NumPy (PyData SV 2013)
 
Introduction to Gura Programming Language
Introduction to Gura Programming LanguageIntroduction to Gura Programming Language
Introduction to Gura Programming Language
 
NumPy/SciPy Statistics
NumPy/SciPy StatisticsNumPy/SciPy Statistics
NumPy/SciPy Statistics
 
Introduction to matplotlib
Introduction to matplotlibIntroduction to matplotlib
Introduction to matplotlib
 
Закон Деметры / Demetra's law
Закон Деметры / Demetra's lawЗакон Деметры / Demetra's law
Закон Деметры / Demetra's law
 
Intoduction to numpy
Intoduction to numpyIntoduction to numpy
Intoduction to numpy
 
A peek on numerical programming in perl and python e christopher dyken 2005
A peek on numerical programming in perl and python  e christopher dyken  2005A peek on numerical programming in perl and python  e christopher dyken  2005
A peek on numerical programming in perl and python e christopher dyken 2005
 
Numpy
NumpyNumpy
Numpy
 
Tensor board
Tensor boardTensor board
Tensor board
 
NUMPY
NUMPY NUMPY
NUMPY
 
C Programming: Pointer (Examples)
C Programming: Pointer (Examples)C Programming: Pointer (Examples)
C Programming: Pointer (Examples)
 
Deep learning for Junior Developer
Deep learning for Junior DeveloperDeep learning for Junior Developer
Deep learning for Junior Developer
 
[DevDay2019] Python Machine Learning with Jupyter Notebook - By Nguyen Huu Th...
[DevDay2019] Python Machine Learning with Jupyter Notebook - By Nguyen Huu Th...[DevDay2019] Python Machine Learning with Jupyter Notebook - By Nguyen Huu Th...
[DevDay2019] Python Machine Learning with Jupyter Notebook - By Nguyen Huu Th...
 
Python for Scientific Computing -- Ricardo Cruz
Python for Scientific Computing -- Ricardo CruzPython for Scientific Computing -- Ricardo Cruz
Python for Scientific Computing -- Ricardo Cruz
 
Shape Safety in Tensor Programming is Easy for a Theorem Prover -SBTB 2021
Shape Safety in Tensor Programming is Easy for a Theorem Prover -SBTB 2021Shape Safety in Tensor Programming is Easy for a Theorem Prover -SBTB 2021
Shape Safety in Tensor Programming is Easy for a Theorem Prover -SBTB 2021
 
Finding root of equation (numarical method)
Finding root of equation (numarical method)Finding root of equation (numarical method)
Finding root of equation (numarical method)
 
Breadth first search signed
Breadth first search signedBreadth first search signed
Breadth first search signed
 
Pythonbrasil - 2018 - Acelerando Soluções com GPU
Pythonbrasil - 2018 - Acelerando Soluções com GPUPythonbrasil - 2018 - Acelerando Soluções com GPU
Pythonbrasil - 2018 - Acelerando Soluções com GPU
 

Similaire à Session1

Session2
Session2Session2
Session2vattam
 
GoLightly: Building VM-Based Language Runtimes with Google Go
GoLightly: Building VM-Based Language Runtimes with Google GoGoLightly: Building VM-Based Language Runtimes with Google Go
GoLightly: Building VM-Based Language Runtimes with Google GoEleanor McHugh
 
Scalapeno18 - Thinking Less with Scala
Scalapeno18 - Thinking Less with ScalaScalapeno18 - Thinking Less with Scala
Scalapeno18 - Thinking Less with ScalaDaniel Sebban
 
Artificial intelligence - python
Artificial intelligence - pythonArtificial intelligence - python
Artificial intelligence - pythonSunjid Hasan
 
PLOTCON NYC: PlotlyJS.jl: Interactive plotting in Julia
PLOTCON NYC: PlotlyJS.jl: Interactive plotting in JuliaPLOTCON NYC: PlotlyJS.jl: Interactive plotting in Julia
PLOTCON NYC: PlotlyJS.jl: Interactive plotting in JuliaPlotly
 
Python于Web 2.0网站的应用 - QCon Beijing 2010
Python于Web 2.0网站的应用 - QCon Beijing 2010Python于Web 2.0网站的应用 - QCon Beijing 2010
Python于Web 2.0网站的应用 - QCon Beijing 2010Qiangning Hong
 
Advanced_Python_Programming.pdf
Advanced_Python_Programming.pdfAdvanced_Python_Programming.pdf
Advanced_Python_Programming.pdfvamshikkrishna1
 
David M. Beazley - Advanced Python Programming (2000, O'Reilly).pdf
David M. Beazley - Advanced Python Programming (2000, O'Reilly).pdfDavid M. Beazley - Advanced Python Programming (2000, O'Reilly).pdf
David M. Beazley - Advanced Python Programming (2000, O'Reilly).pdfphptr
 
ODU ACM Python & Memento Presentation
ODU ACM Python & Memento PresentationODU ACM Python & Memento Presentation
ODU ACM Python & Memento PresentationScottAinsworth
 
SociaLite: High-level Query Language for Big Data Analysis
SociaLite: High-level Query Language for Big Data AnalysisSociaLite: High-level Query Language for Big Data Analysis
SociaLite: High-level Query Language for Big Data AnalysisDataWorks Summit
 
Kotlin Slides from Devoxx 2011
Kotlin Slides from Devoxx 2011Kotlin Slides from Devoxx 2011
Kotlin Slides from Devoxx 2011Andrey Breslav
 
IAT334-Lab02-ArraysPImage.pptx
IAT334-Lab02-ArraysPImage.pptxIAT334-Lab02-ArraysPImage.pptx
IAT334-Lab02-ArraysPImage.pptxssuseraae9cd
 
CS4200 2019 | Lecture 5 | Transformation by Term Rewriting
CS4200 2019 | Lecture 5 | Transformation by Term RewritingCS4200 2019 | Lecture 5 | Transformation by Term Rewriting
CS4200 2019 | Lecture 5 | Transformation by Term RewritingEelco Visser
 
Python for data science by www.dmdiploma.com
Python for data science by www.dmdiploma.comPython for data science by www.dmdiploma.com
Python for data science by www.dmdiploma.comShwetaAggarwal56
 
Lecture 5 – Computing with Numbers (Math Lib).pptx
Lecture 5 – Computing with Numbers (Math Lib).pptxLecture 5 – Computing with Numbers (Math Lib).pptx
Lecture 5 – Computing with Numbers (Math Lib).pptxjovannyflex
 
Lecture 5 – Computing with Numbers (Math Lib).pptx
Lecture 5 – Computing with Numbers (Math Lib).pptxLecture 5 – Computing with Numbers (Math Lib).pptx
Lecture 5 – Computing with Numbers (Math Lib).pptxjovannyflex
 

Similaire à Session1 (20)

Session2
Session2Session2
Session2
 
GoLightly: Building VM-Based Language Runtimes with Google Go
GoLightly: Building VM-Based Language Runtimes with Google GoGoLightly: Building VM-Based Language Runtimes with Google Go
GoLightly: Building VM-Based Language Runtimes with Google Go
 
Scalapeno18 - Thinking Less with Scala
Scalapeno18 - Thinking Less with ScalaScalapeno18 - Thinking Less with Scala
Scalapeno18 - Thinking Less with Scala
 
Artificial intelligence - python
Artificial intelligence - pythonArtificial intelligence - python
Artificial intelligence - python
 
PLOTCON NYC: PlotlyJS.jl: Interactive plotting in Julia
PLOTCON NYC: PlotlyJS.jl: Interactive plotting in JuliaPLOTCON NYC: PlotlyJS.jl: Interactive plotting in Julia
PLOTCON NYC: PlotlyJS.jl: Interactive plotting in Julia
 
Python于Web 2.0网站的应用 - QCon Beijing 2010
Python于Web 2.0网站的应用 - QCon Beijing 2010Python于Web 2.0网站的应用 - QCon Beijing 2010
Python于Web 2.0网站的应用 - QCon Beijing 2010
 
Advanced_Python_Programming.pdf
Advanced_Python_Programming.pdfAdvanced_Python_Programming.pdf
Advanced_Python_Programming.pdf
 
David M. Beazley - Advanced Python Programming (2000, O'Reilly).pdf
David M. Beazley - Advanced Python Programming (2000, O'Reilly).pdfDavid M. Beazley - Advanced Python Programming (2000, O'Reilly).pdf
David M. Beazley - Advanced Python Programming (2000, O'Reilly).pdf
 
Python.pdf
Python.pdfPython.pdf
Python.pdf
 
ODU ACM Python & Memento Presentation
ODU ACM Python & Memento PresentationODU ACM Python & Memento Presentation
ODU ACM Python & Memento Presentation
 
SociaLite: High-level Query Language for Big Data Analysis
SociaLite: High-level Query Language for Big Data AnalysisSociaLite: High-level Query Language for Big Data Analysis
SociaLite: High-level Query Language for Big Data Analysis
 
Kotlin @ Devoxx 2011
Kotlin @ Devoxx 2011Kotlin @ Devoxx 2011
Kotlin @ Devoxx 2011
 
Kotlin Slides from Devoxx 2011
Kotlin Slides from Devoxx 2011Kotlin Slides from Devoxx 2011
Kotlin Slides from Devoxx 2011
 
Python Puzzlers
Python PuzzlersPython Puzzlers
Python Puzzlers
 
IAT334-Lab02-ArraysPImage.pptx
IAT334-Lab02-ArraysPImage.pptxIAT334-Lab02-ArraysPImage.pptx
IAT334-Lab02-ArraysPImage.pptx
 
CS4200 2019 | Lecture 5 | Transformation by Term Rewriting
CS4200 2019 | Lecture 5 | Transformation by Term RewritingCS4200 2019 | Lecture 5 | Transformation by Term Rewriting
CS4200 2019 | Lecture 5 | Transformation by Term Rewriting
 
Python for data science by www.dmdiploma.com
Python for data science by www.dmdiploma.comPython for data science by www.dmdiploma.com
Python for data science by www.dmdiploma.com
 
Python slide
Python slidePython slide
Python slide
 
Lecture 5 – Computing with Numbers (Math Lib).pptx
Lecture 5 – Computing with Numbers (Math Lib).pptxLecture 5 – Computing with Numbers (Math Lib).pptx
Lecture 5 – Computing with Numbers (Math Lib).pptx
 
Lecture 5 – Computing with Numbers (Math Lib).pptx
Lecture 5 – Computing with Numbers (Math Lib).pptxLecture 5 – Computing with Numbers (Math Lib).pptx
Lecture 5 – Computing with Numbers (Math Lib).pptx
 

Dernier

URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 

Dernier (20)

URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 

Session1

  • 1. Python for Science and Engg: Interactive Plotting FOSSEE Department of Aerospace Engineering IIT Bombay 12 February, 2010 Day 1, Session 1 FOSSEE (IIT Bombay) Interactive Plotting 1 / 34
  • 2. Workshop Schedule: Day 1 Session 1 Fri 14:00–15:00 Session 2 Fri 15:05–16:05 Session 3 Fri 16:10–17:10 Quiz 1 Fri 17:10–17:25 Exercises Thu 17:30–18:00 FOSSEE (IIT Bombay) Interactive Plotting 2 / 34
  • 3. Workshop Schedule: Day 2 Session 1 Sat 09:00–10:00 Session 2 Sat 10:05–11:05 Session 3 Sat 11:20–12:20 Quiz 2 Fri 14:25–14:40 FOSSEE (IIT Bombay) Interactive Plotting 3 / 34
  • 4. Workshop Schedule: Day 3 Session 1 Sun 09:00–10:00 Session 2 Sun 10:05–11:05 Session 3 Sun 11:20–12:20 Quiz 3 Sun 12:20–12:30 Exercises Sun 12:30–13:00 FOSSEE (IIT Bombay) Interactive Plotting 4 / 34
  • 5. Checklist Outline 1 Checklist 2 Starting up Ipython 3 Loops 4 Plotting Drawing plots Decoration More decoration 5 Multiple plots FOSSEE (IIT Bombay) Interactive Plotting 5 / 34
  • 6. Checklist Checklist 1 IPython 2 Editor 3 Data files: sslc1.txt pendulum.txt points.txt pos.txt holmes.txt 4 Python scripts: sslc_allreg.py sslc_science.py 5 Images lena.png smoothing.gif FOSSEE (IIT Bombay) Interactive Plotting 6 / 34
  • 7. Checklist About the Workshop Intended Audience Engg., Mathematics and Science teachers. Interested students from similar streams. Goal: Successful participants will be able to Use Python as plotting, computational tool. Understand how to use Python as a scripting and problem solving language. Train students for the same. FOSSEE (IIT Bombay) Interactive Plotting 7 / 34
  • 8. Starting up Ipython Outline 1 Checklist 2 Starting up Ipython 3 Loops 4 Plotting Drawing plots Decoration More decoration 5 Multiple plots FOSSEE (IIT Bombay) Interactive Plotting 8 / 34
  • 9. Starting up Ipython Starting up . . . $ ipython -pylab In []: print "Hello, World!" Hello, World! Exiting In []: ^D(Ctrl-D) Do you really want to exit([y]/n)? y FOSSEE (IIT Bombay) Interactive Plotting 9 / 34
  • 10. Loops Outline 1 Checklist 2 Starting up Ipython 3 Loops 4 Plotting Drawing plots Decoration More decoration 5 Multiple plots FOSSEE (IIT Bombay) Interactive Plotting 10 / 34
  • 11. Loops Loops Breaking out of loops In []: while True: ...: print "Hello, World!" ...: Hello, World! Hello, World!^C(Ctrl-C) ------------------------------------ KeyboardInterrupt FOSSEE (IIT Bombay) Interactive Plotting 11 / 34
  • 12. Plotting Outline 1 Checklist 2 Starting up Ipython 3 Loops 4 Plotting Drawing plots Decoration More decoration 5 Multiple plots FOSSEE (IIT Bombay) Interactive Plotting 12 / 34
  • 13. Plotting Drawing plots Outline 1 Checklist 2 Starting up Ipython 3 Loops 4 Plotting Drawing plots Decoration More decoration 5 Multiple plots FOSSEE (IIT Bombay) Interactive Plotting 13 / 34
  • 14. Plotting Drawing plots First Plot In []: x = linspace(0, 2*pi, 50) In []: plot(x, sin(x)) FOSSEE (IIT Bombay) Interactive Plotting 14 / 34
  • 15. Plotting Drawing plots Walkthrough x = linspace(start, stop, num) returns num evenly spaced points, in the interval [start, stop]. x[0] = start x[num - 1] = end plot(x, y) plots x and y using default line style and color FOSSEE (IIT Bombay) Interactive Plotting 15 / 34
  • 16. Plotting Decoration Outline 1 Checklist 2 Starting up Ipython 3 Loops 4 Plotting Drawing plots Decoration More decoration 5 Multiple plots FOSSEE (IIT Bombay) Interactive Plotting 16 / 34
  • 17. Plotting Decoration Adding Labels In []: xlabel(’x’) In []: ylabel(’sin(x)’) FOSSEE (IIT Bombay) Interactive Plotting 17 / 34
  • 18. Plotting Decoration Another example In []: clf() Clears the plot area. In []: y = linspace(0, 2*pi, 50) In []: plot(y, sin(2*y)) In []: xlabel(’y’) In []: ylabel(’sin(2y)’) FOSSEE (IIT Bombay) Interactive Plotting 18 / 34
  • 19. Plotting More decoration Outline 1 Checklist 2 Starting up Ipython 3 Loops 4 Plotting Drawing plots Decoration More decoration 5 Multiple plots FOSSEE (IIT Bombay) Interactive Plotting 19 / 34
  • 20. Plotting More decoration Title and Legends In []: title(’Sinusoids’) In []: legend([’sin(2y)’]) FOSSEE (IIT Bombay) Interactive Plotting 20 / 34
  • 21. Plotting More decoration Legend Placement In []: legend([’sin(2y)’], loc = ’center’) ’best’ ’right’ ’center’ FOSSEE (IIT Bombay) Interactive Plotting 21 / 34
  • 22. Plotting More decoration Saving & Closing In []: savefig(’sin.png’) In []: close() FOSSEE (IIT Bombay) Interactive Plotting 22 / 34
  • 23. Multiple plots Outline 1 Checklist 2 Starting up Ipython 3 Loops 4 Plotting Drawing plots Decoration More decoration 5 Multiple plots FOSSEE (IIT Bombay) Interactive Plotting 23 / 34
  • 24. Multiple plots Overlaid Plots In []: clf() In []: plot(y, sin(y)) In []: plot(y, cos(y)) In []: xlabel(’y’) In []: ylabel(’f(y)’) In []: legend([’sin(y)’, ’cos(y)’]) By default plots would be overlaid! FOSSEE (IIT Bombay) Interactive Plotting 24 / 34
  • 25. Multiple plots Plotting separate figures In []: clf() In []: figure(1) In []: plot(y, sin(y)) In []: figure(2) In []: plot(y, cos(y)) In []: savefig(’cosine.png’) In []: figure(1) In []: title(’sin(y)’) In []: savefig(’sine.png’) In []: close() In []: close() FOSSEE (IIT Bombay) Interactive Plotting 25 / 34
  • 26. Multiple plots Showing it better In []: plot(y, cos(y), ’r’) In []: clf() In []: plot(y, sin(y), ’g’, linewidth=2) FOSSEE (IIT Bombay) Interactive Plotting 26 / 34
  • 27. Multiple plots Annotating In []: annotate(’local max’, xy=(1.5, 1)) FOSSEE (IIT Bombay) Interactive Plotting 27 / 34
  • 28. Multiple plots Axes lengths Get the axes limits In []: xmin, xmax = xlim() In []: ymin, ymax = ylim() Set the axes limits In []: xlim(xmin, 2*pi) In []: ylim(ymin-0.2, ymax+0.2) FOSSEE (IIT Bombay) Interactive Plotting 28 / 34
  • 29. Multiple plots Review Problem 1 Plot x, -x, sin(x), xsin(x) in range −5π to 5π 2 Add a legend 3 Annotate the origin 4 Set axes limits to the range of x FOSSEE (IIT Bombay) Interactive Plotting 29 / 34
  • 30. Multiple plots Review Problem . . . Plotting . . . In []: x=linspace(-5*pi, 5*pi, 500) In []: plot(x, x, ’b’) In []: plot(x, -x, ’b’) In []: plot(x, sin(x), ’g’, linewidth=2) In []: plot(x, x*sin(x), ’r’, linewidth=3) . . . FOSSEE (IIT Bombay) Interactive Plotting 30 / 34
  • 31. Multiple plots Review Problem . . . Legend & Annotation. . . In []: legend([’x’, ’-x’, ’sin(x)’, ’xsin(x)’]) In []: annotate(’origin’, xy = (0, 0)) Setting Axes limits. . . In []: xlim(-5*pi, 5*pi) In []: ylim(-5*pi, 5*pi) FOSSEE (IIT Bombay) Interactive Plotting 31 / 34
  • 32. Multiple plots Saving Commands Save commands of review problem into file Use %hist command of IPython Identify the required line numbers Then, use %save command of IPython In []: %hist In []: %save four_plot.py 16 18-27 Careful about errors! %hist will contain the errors as well, so be careful while selecting line numbers. FOSSEE (IIT Bombay) Interactive Plotting 32 / 34
  • 33. Multiple plots Python Scripts. . . This is called a Python Script. run the script in IPython using %run -i four_plot.py FOSSEE (IIT Bombay) Interactive Plotting 33 / 34
  • 34. Multiple plots What did we learn? Starting up IPython %hist - History of commands %save - Saving commands Running a script using %run -i Creating simple plots. Adding labels and legends. Annotating plots. Changing the looks: size, linewidth FOSSEE (IIT Bombay) Interactive Plotting 34 / 34