Web-Books
in the Austria-Forum
Austria-Forum
Web-Books
Informatik
Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python
Page - 20 -
  • User
  • Version
    • full version
    • text only version
  • Language
    • Deutsch - German
    • English

Page - 20 - in Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python

Image of the Page - 20 -

Image of the Page - 20 - in Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python

Text of the Page - 20 -

20 1 TheFirstFewSteps Thenyoucould (inprinciple)doa lot ofother things inyourcode,beforeyouplot thesecondcurveby plt.plot(family_member_no, H) plt.hold(’off’) Notice the use ofhold here. hold(’on’) tells Python to plot also the following curve(s) in the samewindow. Python does so until it readshold(’off’). If you donotuse thehold(’on’)orhold(’off’)command, the secondplot command will overwrite thefirstone, i.e., yougetonly the secondcurve. In case youwould like the two curvesplotted in two separate plots, youcando thisbyplotting thefirst curvestraightforwardlywith plt.plot(family_member_no, h) thendoother things inyourcode,beforeyoudo plt.figure() plt.plot(family_member_no, H) Note how the graphs are made continuous by Python, drawing straight lines be- tween the fourdata points of each family. This is the standardwayofdoing it and wasalsodonewhenplottingour1001heightcomputationswithball_plot.py in Chapter1.4.However, since therewere somanydatapoints then, thecurve looked niceandsmooth. Ifpreferred,onemayalsoplotonly thedatapoints. For example, writing plt.plot(h, ’*’) willmarkonly thedatapointswith the star symbol.Other symbols like circles etc. maybeusedaswell. There aremany possibilities in Python for adding information to a plot or for changing its appearance. For example,youmayadda legendby the instruction plt.legend(’This is some legend’) oryoumayadda title by plt.title(’This is some title’) Thecommand plt.axis([xmin, xmax, ymin, ymax]) will define the plotting range for the x axis to stretch from xmin to xmax and, similarly, theplotting range for they axis fromymin toymax. Saving thefigure to file is achievedby thecommand
back to the  book Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python"
Programming for Computations – Python A Gentle Introduction to Numerical Simulations with Python
Title
Programming for Computations – Python
Subtitle
A Gentle Introduction to Numerical Simulations with Python
Authors
Svein Linge
Hans Petter Langtangen
Publisher
Springer Open
Date
2016
Language
English
License
CC BY-NC 4.0
ISBN
978-3-319-32428-9
Size
17.8 x 25.4 cm
Pages
248
Keywords
Programmiersprache, Informatik, programming language, functional, imperative, object-oriented, reflective
Category
Informatik
Web-Books
Library
Privacy
Imprint
Austria-Forum
Austria-Forum
Web-Books
Programming for Computations – Python