curve-fitting

Python curve fitting on a barplot

你说的曾经没有我的故事 提交于 2019-12-08 07:12:57
问题 How do I fit a curve on a barplot? I have an equation, the diffusion equation, which has some unknown parameters, these parameters make the curve larger, taller, etc. On the other hand I have a barplot coming from a simulation. I would like to fit the curve on the barplot, and find the best parameters for the curve, how can I do that? This is what I obtained by 'manual fitting', so basically I changed manually all the parameters for hours. However is there a way to do this with python? To

Finding midlines of polygons using Voronoi diagrams

泪湿孤枕 提交于 2019-12-08 06:56:27
问题 I am using the Voronoi diagram-based approach outlined here to find midlines of binary masks of root images. I am using the Python code more or less exactly as described: import skimage.morphology as morphology WHITE = 255 image_bool = binary_mask == WHITE d = morphology.disk(2) img = morphology.binary_closing(image_bool, selem=d) skeleton = morphology.medial_axis(img) Then comes the graphing: I feed the skeletonized image into buildTree, as described in user Gabriel's iPython notebook: https

scipy curve fitting negative value

耗尽温柔 提交于 2019-12-08 05:57:02
问题 I would like to fit a curve with curve_fit and prevent it from becoming negative. Unfortunately, the code below does not work. Any hints? Thanks a lot! # Imports from scipy.optimize import curve_fit import numpy as np import matplotlib.pyplot as plt xData = [0.0009824379203203417, 0.0011014182912933933, 0.0012433979929054324, 0.0014147106052612918, 0.0016240300315499524, 0.0018834904507916608, 0.002210485320720769, 0.002630660216394964, 0.0031830988618379067, 0.003929751681281367, 0

how to calculate control points on a bezier curve?

倾然丶 夕夏残阳落幕 提交于 2019-12-08 01:18:36
问题 I do have a bezier curve, and at a certain point, I want a second bezier curve "branching off" the first curve in a smooth manner. Together with calculating the intersection point (with a percentage following the Bezier curve), I need also the control point (the tangent and weight). The intersection point is calculated with the following piece of javascript: getBezier = function getBez(percent,p1,cp1,cp2,p2) { function b1(t) { return t*t*t } function b2(t) { return 3*t*t*(1-t) } function b3(t

How can I fit a cosine function?

爱⌒轻易说出口 提交于 2019-12-08 00:55:33
问题 I wrote a python function to get the parameters of the following cosine function: param = Parameters() param.add( 'amp', value = amp_guess, min = 0.1 * amp_guess, max = amp_guess ) param.add( 'off', value = off_guess, min = -10, max = 10 ) param.add( 'shift', value = shift_guess[0], min = 0, max = 2 * np.pi, ) fit_values = minimize( self.residual, param, args = ( azi_unique, los_unique ) ) def residual( self, param, azi, data ): """ Parameters ---------- Returns ------- """ amp = param['amp']

Strange result with python's (scipy) curve fitting

浪子不回头ぞ 提交于 2019-12-07 21:12:22
问题 This is my code (it's an example of a larger piece of code): from scipy.optimize import curve_fit def func(x, a, b): return a + b*x xlist = [10, 30, 50, 70, 90, 110, 130, 150, 170, 190, 210, 230] ylist = [0.0074999999999999997, 0.011875, 0.0057812499999999999, 0.0036458333333333334, 0.0020312500000000001, 0.0013125000000000001, 0.00098958333333333342, 0.00089285714285714283, 0.00074218750000000001, 0.00093749999999999997, 0.00071874999999999999, 0.00088068181818181821] popt, pcov = curve_fit

curve fitting with a known function numpy

≡放荡痞女 提交于 2019-12-07 19:30:24
问题 I have a x and y one-dimension numpy array and I would like to reproduce y with a known function to obtain "beta". Here is the code I am using: import numpy as np import matplotlib.pyplot as plt from scipy.optimize import curve_fit y = array([ 0.04022493, 0.04287536, 0.03983657, 0.0393201 , 0.03810298, 0.0363814 , 0.0331144 , 0.03074823, 0.02795767, 0.02413816, 0.02180802, 0.01861309, 0.01632699, 0.01368056, 0.01124232, 0.01005323, 0.00867196, 0.00940864, 0.00961282, 0.00892419, 0.01048963, 0

Getting percentile values from gamlss centile curves

会有一股神秘感。 提交于 2019-12-07 18:51:32
问题 This question is related to: Selecting Percentile curves using gamlss::lms in R I can get centile curve from following data and code: age = sample(5:15, 500, replace=T) yvar = rnorm(500, age, 20) mydata = data.frame(age, yvar) head(mydata) age yvar 1 12 13.12974 2 14 -18.97290 3 10 42.11045 4 12 27.89088 5 11 48.03861 6 5 24.68591 h = lms(yvar, age , data=mydata, n.cyc=30) centiles(h,xvar=mydata$age, cent=c(90), points=FALSE) How can I now get yvar on the curve for each of x value (5:15)

passing arguments to a function for fitting

浪子不回头ぞ 提交于 2019-12-07 17:31:20
问题 I am trying to fit a function which takes as input 2 independent variables x,y and 3 parameters to be found a,b,c. This is my test code: import numpy as np from scipy.optimize import curve_fit def func(x,y, a, b, c): return a*np.exp(-b*(x+y)) + c y= x = np.linspace(0,4,50) z = func(x,y, 2.5, 1.3, 0.5) #works ok #generate data to be fitted zn = z + 0.2*np.random.normal(size=len(x)) popt, pcov = curve_fit(func, x,y, zn) #<--------Problem here!!!!! But i am getting the error: "func() takes

Selecting Percentile curves using gamlss::lms in R

回眸只為那壹抹淺笑 提交于 2019-12-07 17:02:31
I am using example code from gamlss package to draw percentile curves: library(gamlss) data(abdom) lms(y,x , data=abdom, n.cyc=30) It is drawing its own set of percentile curves. How can I choose to draw only 10th, 50th and 90th percentile curves? Also I want to avoid plotting of points so that only curves are drawn. Thanks for your help. It's always a good idea to read the help pages: > centiles(h,xvar=abdom$x, cent=c(10,50,90), points=FALSE) % of cases below 10 centile is 8.688525 % of cases below 50 centile is 50.16393 % of cases below 90 centile is 90 来源: https://stackoverflow.com