How to: Import, Plot, Fit, and Integrate Data in Python

preview_player
Показать описание
Learn how to import and visualize a ".csv" data set into Python. Also, how to do a linear least-squares curve fit to a function and integrate the data.

Here we use "Spyder" IDE as the Python Shell and the following libraries: numpy, csv, matplotlib, and scipy

Here is the script:

import numpy as np
import csv
from scipy import integrate as intg


xdata = exampledata[:,0]
ydata = exampledata[:,1]

def func(x,b): #input x in nm and b in nm^-1

a0 = 2.5 #W m^-2 nm^-1
a1 = 0.5 #W m^-2 nm^-1

funcdata = func(xdata,1.375) #Generate & Plot data for comparison

popt, pcov = curve_fit(func,xdata,ydata,bounds=(0,4))

Рекомендации по теме
Комментарии
Автор

Correction: In "curve_fit", the bounds should be bounds for fitting the desired parameter (e.g. popt must lie in this range). This bound has nothing to do with the xdata!

hageslab
Автор

Great stuff. Basic, simple and practical. Why is there so little of the Python videos here like this.

maramarsu
Автор

Thank you for this, I was looking for a curve fit algo and didn't know scipy had one :) Also you go straight to the point, much appreciated !

jazzgenerator
Автор

That's an awesome tutorial. It was so easy to understand the codes. Great work!!

shkb
Автор

Thank you so much, your videos are useful as hell... i think you saved me a whole day of work =D

simone
Автор

the man right here, wish I could thumbs up more than once, already tried a few times

pgille
Автор

thanks, very clear explination and was also interesting to see spyder used for investigation rather than jupyter lab

Oceansteve
Автор

thank you, this is an awesome primer.

uber-jaianada
Автор

Cool video. This I like a lot. Thanks for the helpful instructions.

emmanuelschmulewitz
Автор

Thanks for this tutorial! I have a project that requires the integration of an acceleration data set twice two get position, however, I was wondering how to go about plotting the integrated curve of acceleration to get velocity and the integrated curve of velocity to get position. Would you be able to provide any insight on this please?

corinwong
Автор

@HagesLab, thank a lot and wonderful tutorial, it will be more interesting and disrupt if you do reverse engineering (from image/graph image, extract data points to .csv)

Surtinsumos
Автор

Thank uu Thank uuu Thankk uuu.!!! Just Thank uu❤️

subhankarmajumder
Автор

I love the simple but very instructive way of presentation in your videos. I want to know if you run online tutorial classes for python in spyder IDE for beginners like myself so interested persons can register and be taught...I am really interested if you do such. keep it up. cheers!

emmanuelokpas
Автор

Nice tutorial. Thank you. I was wondering if there is any inbuilt library available in python to get the uncertainty in integration due to the uncertainty in the fit parameters.

abinashpun
Автор

Hi, good work. Thanks for your efforts

kajwalkumarpatra
Автор

Can you explain about libraries for to do integrations from data files? and for example, How to do adaptative integration?

Markosiiiiii
Автор

Nice video, but how can I subtract the set of my data points to the points in the curve line?

matthewluna
Автор

Excellent video, am now a subscriber. Two questions of practical important for many of your students. First, how to modify the curve_fit command to perform the regression using robust treatment of errors? Am performing analysis where distances are the dependent variable, and we all know that the errors of far distant objects are sometimes best treated as relatively unimportant. Second, need to display the standard deviations of the parameters - how best to do this?

michaelsmith
Автор

Good work! Thank you so much! Still one confusion remains, i have two curves each x and y values are different from two samples. I need to plot both in python, then find the average of their curves. As Microsoft Excel has no built in function to do it. How can i do it in Python?

civilacademia
Автор

Thank you for the tutorial. Can it still work without using spyder. Using python IDLE?

chalcool