Web-Books
im Austria-Forum
Austria-Forum
Web-Books
Informatik
Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python 3.6, Band Second Edition
Seite - 25 -
  • Benutzer
  • Version
    • Vollversion
    • Textversion
  • Sprache
    • Deutsch
    • English - Englisch

Seite - 25 - in Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python 3.6, Band Second Edition

Bild der Seite - 25 -

Bild der Seite - 25 - in Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python 3.6, Band Second Edition

Text der Seite - 25 -

1.6 Plotting,PrintingandInputData 25 t = np.linspace(-2, 2, 100) # choose 100 points in time interval f_values = t**2 g_values = np.exp(t) plt.plot(t, f_values, ’r’, t, g_values, ’b--’) plt.xlabel(’t’) plt.ylabel(’f and g’) plt.legend([’t**2’, ’e**t’]) plt.title(’Plotting of two functions (t**2 and e**t)’) plt.grid(’on’) plt.axis([-3, 3, -1, 10]) plt.show() In thiscode,yourecognizethecommandsexplainedjust above.Their impacton theplotmaybe seen inFig.1.3,which is producedwhen theprogramisexecuted. Fig. 1.3 The functionsf(t)= t2 andg(t)= et Inaddition,yousee how plt.plot(t, f_values, ’r’, t, g_values, ’b--’) causesbothcurves tobe seen in the sameplot.Notice thestructurehere,within the parenthesis, we first describe plotting of the one curve with t, f_values, ’r’, before plotting of the second curve is specified by t, g_values, ’b--’. These two “plot specifications” are separated by a comma. Had there been more curves to plot in the same plot, we would simply extend the list in a similar way. For each curve,colorandlinestyleisspecifiedindependentlyoftheothercurvespecifications in the plot command(no specification givesdefault appearance).Furthermore,you noticehow plt.legend([’t**2’, ’e**t’]) creates the right labelling of the curves. Note that the order of curve specifications in the plot command must be the same as the order of legend specifications in
zurück zum  Buch Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python 3.6, Band Second Edition"
Programming for Computations – Python A Gentle Introduction to Numerical Simulations with Python 3.6, Band Second Edition
Titel
Programming for Computations – Python
Untertitel
A Gentle Introduction to Numerical Simulations with Python 3.6
Band
Second Edition
Autoren
Svein Linge
Hans Petter Langtangen
Verlag
Springer Open
Datum
2020
Sprache
englisch
Lizenz
CC BY 4.0
ISBN
978-3-319-32428-9
Abmessungen
17.8 x 25.4 cm
Seiten
356
Schlagwörter
Programmiersprache, Informatik, programming language, functional, imperative, object-oriented, reflective
Kategorie
Informatik
Web-Books
Bibliothek
Datenschutz
Impressum
Austria-Forum
Austria-Forum
Web-Books
Programming for Computations – Python