Data Analysis In Python

Publié le: 31 mars 2023
sur la chaîne: Physics Lectures by Erica
131
2

A Tutorial on Analyzing/Plotting Data using Python.

Code
__________________________________________________
import csv
import numpy as np
import matplotlib.pyplot as plt


t = []
x = []
s = []

with open('speed.csv', newline='') as csvfile:
datareader = csv.reader(csvfile, delimiter=' ', quotechar='|')

for row in datareader:
print(','.join(row))
t.append(float(row[0].split(',')[0]))
x.append(float(row[0].split(',')[1]))
s.append(float(row[0].split(',')[2]))

ts = t
t = np.divide(t,60*60)

print(t)
print(x)
print(s)


plt.close('all')

plt.subplot(2,1,1)
plt.plot(ts,x,'bd-')
thefit = np.polyfit(t,x,1)
plt.plot(ts,np.multiply(t,thefit[0])+thefit[1],'r')
plt.xlabel('Time (s)')
plt.ylabel('Distance (miles)')


plt.subplot(2,1,2)
plt.plot(ts,s,'go-')
speed= np.divide(np.diff(x),np.diff(t))
plt.plot(ts[1:]-np.average(np.diff(ts))/2,speed,'rd-')
plt.xlabel('Time (s)')
plt.ylabel('Speed (mph)')

plt.show()

__________________________________________________
Data
__________________________________________________
0,0,0
14.7,0.1,38
23.1,0.2,40
31.7,0.3,39
41.8,0.4,31
55.2,0.5,30
66.1,0.6,40
74.2,0.7,41
82.1,0.8,43
90.4,0.9,40
102.7,1,20
113.5,1.1,35

________________________________________
#python #data #plotting #analysis


Sur cette page du site, vous pouvez voir la vidéo en ligne Data Analysis In Python durée heure minute seconde en bonne qualité , qui a été Téléchargé par l'utilisateur Physics Lectures by Erica 31 mars 2023, Partagez le lien avec vos amis et connaissances, sur youtube cette vidéo a déjà été regardée 131 fois et il a aimé 2 téléspectateurs. Bon visionnage!