How to: Plot a Function in Python

Publié le: 04 février 2021
sur la chaîne: HagesLab
144,484
1.8k

Learn how to define a function and plot it in Python.

Script can be found here: https://www.hageslab.com/Resources.ht...

Here we are using "Spyder" IDE with the numpy and matplotlib libraries

Useful resources:
https://matplotlib.org/tutorials/text...
https://matplotlib.org/
https://matplotlib.org/3.3.3/api/_as_...

Script:

import numpy as np
import matplotlib.pyplot as plt

def f(x,a,b,c):
return a*x**2+b*x+c

xlist = np.linspace(-10,10,num=1000)
xlist = np.arange(-10,10.1,.1)

a=5
b=1
c=4
ylist = f(xlist,a,b,c)

plt.figure(num=0,dpi=120)
plt.plot(xlist,ylist,label="f(x)")
plt.plot(xlist,ylist**(1/2),'--g',label=r"f(x)$^{0.5}$")
plt.title("Plotting Example")
plt.xlabel("Distance / ft")
plt.ylabel("Height / ft")
plt.legend()


Sur cette page du site, vous pouvez voir la vidéo en ligne How to: Plot a Function in Python durée heure minute seconde en bonne qualité , qui a été Téléchargé par l'utilisateur HagesLab 04 février 2021, Partagez le lien avec vos amis et connaissances, sur youtube cette vidéo a déjà été regardée 144,484 fois et il a aimé 1.8 mille téléspectateurs. Bon visionnage!