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;








3















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()


enter image description here



I would acutally expect some kind of a smooth curve. Can someone explain what I am doing wrong here?










share|improve this question

















  • 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











  • 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

















3















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()


enter image description here



I would acutally expect some kind of a smooth curve. Can someone explain what I am doing wrong here?










share|improve this question

















  • 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











  • 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













3












3








3








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()


enter image description here



I would acutally expect some kind of a smooth curve. Can someone explain what I am doing wrong here?










share|improve this question














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()


enter image description here



I would acutally expect some kind of a smooth curve. Can someone explain what I am doing wrong here?







python scipy curve-fitting






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 25 at 12:29









Jack.O.Jack.O.

719 bronze badges




719 bronze badges







  • 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











  • 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





    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











  • 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












1 Answer
1






active

oldest

votes


















3














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')


smooth






share|improve this answer






















    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
    );



    );













    draft saved

    draft discarded


















    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









    3














    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')


    smooth






    share|improve this answer



























      3














      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')


      smooth






      share|improve this answer

























        3












        3








        3







        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')


        smooth






        share|improve this answer













        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')


        smooth







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 25 at 12:38









        jeremycgjeremycg

        19.3k4 gold badges44 silver badges58 bronze badges




        19.3k4 gold badges44 silver badges58 bronze badges
















            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.




















            draft saved

            draft discarded
















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

            Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript