How do i get a smooth fit for my data points, using “scipy.optimize.curve_fit”?How to get the ASCII value of a character?How to get the current time in PythonHow to get line count cheaply in Python?How do I get the number of elements in a list?How to fit a smooth curve to my data in R?How to get data received in Flask requestHow do I write JSON data to a file?Why does scipy.optimize.curve_fit not fit to the data?Fitted Exponential Curve Errorfsolve mismatch shape error when nonlinear equations solver called from ODE solver
Do space suits measure "methane" levels or other biological gases?
Was it really unprofessional of me to leave without asking for a raise first?
Why transcripts instead of degree certificates?
Can the passive "être + verbe" sometimes mean the past?
Needle Hotend for nonplanar printing
Can a single server be associated with multiple domains?
How was film developed in the late 1920s?
What is a macro? Difference between macro and function?
In native German words, is Q always followed by U, as in English?
Avoid using C Strings on C++ code to trim leading whitespace
"Plugged in" or "Plugged in in"
How hard is it to sell a home which is currently mortgaged?
In F1 classification, what is ON?
Golf the smallest circle!
The Confused Alien
Is it allowed to spend a night in the first entry country before moving to the main destination?
Can I travel from Germany to England alone as an unaccompanied minor?
Questions about authorship rank and academic politics
I hit a pipe with a mower and now it won't turn
What is the line crossing the Pacific Ocean that is shown on maps?
How do researchers used to find articles before the Internet and the computer era?
Which centaur is more 'official'?
How does the Duergar Magic shrink/enlarge ability work with rage?
One folder two different locations on ubuntu 18.04
How do i get a smooth fit for my data points, using “scipy.optimize.curve_fit”?
How to get the ASCII value of a character?How to get the current time in PythonHow to get line count cheaply in Python?How do I get the number of elements in a list?How to fit a smooth curve to my data in R?How to get data received in Flask requestHow do I write JSON data to a file?Why does scipy.optimize.curve_fit not fit to the data?Fitted Exponential Curve Errorfsolve mismatch shape error when nonlinear equations solver called from ODE solver
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I want to fit some data points using scipy.optimize.curve_fit
. Unfortunately I get an unsteady fit and I do not know why.
import numpy as np
import matplotlib.pyplot as plt
from scipy.optimize import curve_fit
M = np.array([730,910,1066,1088,1150], dtype=float)
V = np.array([95.71581923, 146.18564513, 164.46723727, 288.49796413, 370.98703941], dtype=float)
def func(x, a, b, c):
return a * np.exp(b * x) + c
popt, pcov = curve_fit(func, M, V, [0,0,1], maxfev=100000000)
print(*popt)
fig, ax = plt.subplots()
fig.dpi = 80
ax.plot(M, V, 'go', label='data')
ax.plot(M, func(M, *popt), '-', label='fit')
plt.xlabel("M")
plt.ylabel("V")
plt.grid()
plt.legend()
plt.show()
I would acutally expect some kind of a smooth curve. Can someone explain what I am doing wrong here?
python scipy curve-fitting
add a comment |
I want to fit some data points using scipy.optimize.curve_fit
. Unfortunately I get an unsteady fit and I do not know why.
import numpy as np
import matplotlib.pyplot as plt
from scipy.optimize import curve_fit
M = np.array([730,910,1066,1088,1150], dtype=float)
V = np.array([95.71581923, 146.18564513, 164.46723727, 288.49796413, 370.98703941], dtype=float)
def func(x, a, b, c):
return a * np.exp(b * x) + c
popt, pcov = curve_fit(func, M, V, [0,0,1], maxfev=100000000)
print(*popt)
fig, ax = plt.subplots()
fig.dpi = 80
ax.plot(M, V, 'go', label='data')
ax.plot(M, func(M, *popt), '-', label='fit')
plt.xlabel("M")
plt.ylabel("V")
plt.grid()
plt.legend()
plt.show()
I would acutally expect some kind of a smooth curve. Can someone explain what I am doing wrong here?
python scipy curve-fitting
2
Because you are only plotting your function atM, func(M, *popt)
try using something likenp.arange(700,1200), func(np.arange(700,1200), *popt)
– jeremycg
Mar 25 at 12:34
Ouh, that's embarassing..Thank you very much !
– Jack.O.
Mar 25 at 12:37
If it might be of some use, I got an OK fit to a two-parameter hyperbolic type equation "V = (a + M) / (b + M)" with parameters a = -4.8322540715601128E+04 and b = -1.2775297675354102E+03
– James Phillips
Mar 25 at 14:42
add a comment |
I want to fit some data points using scipy.optimize.curve_fit
. Unfortunately I get an unsteady fit and I do not know why.
import numpy as np
import matplotlib.pyplot as plt
from scipy.optimize import curve_fit
M = np.array([730,910,1066,1088,1150], dtype=float)
V = np.array([95.71581923, 146.18564513, 164.46723727, 288.49796413, 370.98703941], dtype=float)
def func(x, a, b, c):
return a * np.exp(b * x) + c
popt, pcov = curve_fit(func, M, V, [0,0,1], maxfev=100000000)
print(*popt)
fig, ax = plt.subplots()
fig.dpi = 80
ax.plot(M, V, 'go', label='data')
ax.plot(M, func(M, *popt), '-', label='fit')
plt.xlabel("M")
plt.ylabel("V")
plt.grid()
plt.legend()
plt.show()
I would acutally expect some kind of a smooth curve. Can someone explain what I am doing wrong here?
python scipy curve-fitting
I want to fit some data points using scipy.optimize.curve_fit
. Unfortunately I get an unsteady fit and I do not know why.
import numpy as np
import matplotlib.pyplot as plt
from scipy.optimize import curve_fit
M = np.array([730,910,1066,1088,1150], dtype=float)
V = np.array([95.71581923, 146.18564513, 164.46723727, 288.49796413, 370.98703941], dtype=float)
def func(x, a, b, c):
return a * np.exp(b * x) + c
popt, pcov = curve_fit(func, M, V, [0,0,1], maxfev=100000000)
print(*popt)
fig, ax = plt.subplots()
fig.dpi = 80
ax.plot(M, V, 'go', label='data')
ax.plot(M, func(M, *popt), '-', label='fit')
plt.xlabel("M")
plt.ylabel("V")
plt.grid()
plt.legend()
plt.show()
I would acutally expect some kind of a smooth curve. Can someone explain what I am doing wrong here?
python scipy curve-fitting
python scipy curve-fitting
asked Mar 25 at 12:29
Jack.O.Jack.O.
719 bronze badges
719 bronze badges
2
Because you are only plotting your function atM, func(M, *popt)
try using something likenp.arange(700,1200), func(np.arange(700,1200), *popt)
– jeremycg
Mar 25 at 12:34
Ouh, that's embarassing..Thank you very much !
– Jack.O.
Mar 25 at 12:37
If it might be of some use, I got an OK fit to a two-parameter hyperbolic type equation "V = (a + M) / (b + M)" with parameters a = -4.8322540715601128E+04 and b = -1.2775297675354102E+03
– James Phillips
Mar 25 at 14:42
add a comment |
2
Because you are only plotting your function atM, func(M, *popt)
try using something likenp.arange(700,1200), func(np.arange(700,1200), *popt)
– jeremycg
Mar 25 at 12:34
Ouh, that's embarassing..Thank you very much !
– Jack.O.
Mar 25 at 12:37
If it might be of some use, I got an OK fit to a two-parameter hyperbolic type equation "V = (a + M) / (b + M)" with parameters a = -4.8322540715601128E+04 and b = -1.2775297675354102E+03
– James Phillips
Mar 25 at 14:42
2
2
Because you are only plotting your function at
M, func(M, *popt)
try using something like np.arange(700,1200), func(np.arange(700,1200), *popt)
– jeremycg
Mar 25 at 12:34
Because you are only plotting your function at
M, func(M, *popt)
try using something like np.arange(700,1200), func(np.arange(700,1200), *popt)
– jeremycg
Mar 25 at 12:34
Ouh, that's embarassing..Thank you very much !
– Jack.O.
Mar 25 at 12:37
Ouh, that's embarassing..Thank you very much !
– Jack.O.
Mar 25 at 12:37
If it might be of some use, I got an OK fit to a two-parameter hyperbolic type equation "V = (a + M) / (b + M)" with parameters a = -4.8322540715601128E+04 and b = -1.2775297675354102E+03
– James Phillips
Mar 25 at 14:42
If it might be of some use, I got an OK fit to a two-parameter hyperbolic type equation "V = (a + M) / (b + M)" with parameters a = -4.8322540715601128E+04 and b = -1.2775297675354102E+03
– James Phillips
Mar 25 at 14:42
add a comment |
1 Answer
1
active
oldest
votes
You are only plotting the same x points as the original data in your call:
ax.plot(M, V, 'go', label='data')
ax.plot(M, func(M, *popt), '-', label='fit')
To fix this, you can use a wider range - here we use all the values from 700 to 1200:
toplot = np.arange(700,1200)
ax.plot(toplot, func(toplot, *popt), '-', label='fit')
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55337817%2fhow-do-i-get-a-smooth-fit-for-my-data-points-using-scipy-optimize-curve-fit%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You are only plotting the same x points as the original data in your call:
ax.plot(M, V, 'go', label='data')
ax.plot(M, func(M, *popt), '-', label='fit')
To fix this, you can use a wider range - here we use all the values from 700 to 1200:
toplot = np.arange(700,1200)
ax.plot(toplot, func(toplot, *popt), '-', label='fit')
add a comment |
You are only plotting the same x points as the original data in your call:
ax.plot(M, V, 'go', label='data')
ax.plot(M, func(M, *popt), '-', label='fit')
To fix this, you can use a wider range - here we use all the values from 700 to 1200:
toplot = np.arange(700,1200)
ax.plot(toplot, func(toplot, *popt), '-', label='fit')
add a comment |
You are only plotting the same x points as the original data in your call:
ax.plot(M, V, 'go', label='data')
ax.plot(M, func(M, *popt), '-', label='fit')
To fix this, you can use a wider range - here we use all the values from 700 to 1200:
toplot = np.arange(700,1200)
ax.plot(toplot, func(toplot, *popt), '-', label='fit')
You are only plotting the same x points as the original data in your call:
ax.plot(M, V, 'go', label='data')
ax.plot(M, func(M, *popt), '-', label='fit')
To fix this, you can use a wider range - here we use all the values from 700 to 1200:
toplot = np.arange(700,1200)
ax.plot(toplot, func(toplot, *popt), '-', label='fit')
answered Mar 25 at 12:38
jeremycgjeremycg
19.3k4 gold badges44 silver badges58 bronze badges
19.3k4 gold badges44 silver badges58 bronze badges
add a comment |
add a comment |
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55337817%2fhow-do-i-get-a-smooth-fit-for-my-data-points-using-scipy-optimize-curve-fit%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
Because you are only plotting your function at
M, func(M, *popt)
try using something likenp.arange(700,1200), func(np.arange(700,1200), *popt)
– jeremycg
Mar 25 at 12:34
Ouh, that's embarassing..Thank you very much !
– Jack.O.
Mar 25 at 12:37
If it might be of some use, I got an OK fit to a two-parameter hyperbolic type equation "V = (a + M) / (b + M)" with parameters a = -4.8322540715601128E+04 and b = -1.2775297675354102E+03
– James Phillips
Mar 25 at 14:42