How to: Plot a Function in Python

Поділитися
Вставка
  • Опубліковано 17 сер 2024
  • Learn how to define a function and plot it in Python.
    Script can be found here: www.hageslab.c...
    Here we are using "Spyder" IDE with the numpy and matplotlib libraries
    Useful resources:
    matplotlib.org...
    matplotlib.org/
    matplotlib.org...
    Script:
    import numpy as np
    import matplotlib.pyplot as plt
    def f(x,a,b,c):
    return a*x**2+b*x+c
    xlist = np.linspace(-10,10,num=1000)
    xlist = np.arange(-10,10.1,.1)
    a=5
    b=1
    c=4
    ylist = f(xlist,a,b,c)
    plt.figure(num=0,dpi=120)
    plt.plot(xlist,ylist,label="f(x)")
    plt.plot(xlist,ylist**(1/2),'--g',label=r"f(x)$^{0.5}$")
    plt.title("Plotting Example")
    plt.xlabel("Distance / ft")
    plt.ylabel("Height / ft")
    plt.legend()
  • Наука та технологія

КОМЕНТАРІ • 37

  • @maramarsu8204
    @maramarsu8204 2 роки тому +11

    You could be a UA-cam hit if you had more material like this. It can be around the similar topics. I enjoined watchin many of your videos even if its close to the same topic. You are great teacher. I have watched many Python youtubers and you one of the best. Pls consider starting making consistent videos weekly so the UA-cam algorithm will pick you up

  • @simone9740
    @simone9740 3 роки тому +6

    THAAAAAAAAAANK YOU so much =D
    I've been looking for such a straight and simple tutorial for so long!

  • @tarehjernetarehjerne4082
    @tarehjernetarehjerne4082 2 роки тому +8

    Hey, thanks a lot for showing this, very clear and easy to follow. Liked

  • @zjason7582
    @zjason7582 Рік тому

    Awesome! Thanks for the clear guide of how to use this matplotlib tool!

  • @elmo45
    @elmo45 Рік тому +2

    I am using VSCODE as my IDE. I could not get the plot window to show up, unless I added plt.show() to thee end of your code. I enjoyed your video, but I wanted to know more about which function outputs the graph, and whether or not this issue is IDE specific (spyder vs vscode)

  • @iriisnes
    @iriisnes 2 роки тому +1

    Excellent content. Subscribed. Commenting for the algorithms.

  • @TuExklusiv
    @TuExklusiv 19 днів тому

    Very good video!

  • @k-xxy8308
    @k-xxy8308 2 роки тому +1

    Thank you so much!! Needed to do something similar for an assignment, this really helped!!

  • @mashedpotato9628
    @mashedpotato9628 2 роки тому +1

    Please include in your title "Spyder". It will help in the search! :)

  • @prestonphillips8373
    @prestonphillips8373 3 роки тому +5

    What code editor are you using?

    • @PinhoDeng
      @PinhoDeng 2 роки тому

      He is using Spyder. It is a programming platform designed to be used by scientists.

  • @chewchengkai2769
    @chewchengkai2769 3 роки тому

    how about if dont know about values of a,b,c and need input ourself, then how to plot the graph

  • @najeebzakariya2346
    @najeebzakariya2346 2 роки тому

    Thank you very much for this Mister.

  • @shinyshadow1
    @shinyshadow1 3 роки тому +1

    awesome. straight, easy, clear -> perfect!

  • @limboski696
    @limboski696 Рік тому

    Having programmed in Python for some time, I found the video confusing because python does not normally perform math operations on an entire list of floats which is what is done in function f here. And, this program would not work if you manually defined xlist with something like xlist = [-10.0, -9.9, ...., 9.9, 10.0]. However, using numpy to create the list does not create a list of floats but instead a class 'numpy.ndarray' object. Python then understands math operations like xlist **2.

  • @anubhavrajyan7963
    @anubhavrajyan7963 2 роки тому

    Worth watching

  • @pratyushpro9060
    @pratyushpro9060 3 роки тому +1

    what is that code editor?

  • @oumaimajanouj6309
    @oumaimajanouj6309 3 роки тому +1

    Great video. But i have a question , when i run my script i can see the plot bit when i save it as an image , there is just white in that image, any idea why??

  • @cristianortiz3349
    @cristianortiz3349 3 роки тому

    Very good

  • @arpitakundu7847
    @arpitakundu7847 6 місяців тому

    Can you please use light mode?

  • @junaid2773
    @junaid2773 2 роки тому

    Very helpful!

  • @coryreedrobbins
    @coryreedrobbins 3 роки тому +2

    these math ones are important... algorithms, plotting, more, please...

  • @keiserhurtadomontano4796
    @keiserhurtadomontano4796 3 роки тому +2

    Thanks for the videos, could you zoom in on the screen to better see the letter of the code? Thank you

    • @hageslab7281
      @hageslab7281  3 роки тому +2

      The full script is also written in the video description

  • @RakeshKumar-he6ek
    @RakeshKumar-he6ek 2 роки тому

    very useful for beginner, thank you;

  • @shibushil4164
    @shibushil4164 2 роки тому

    You should zoom in the coding part..cant see properly,

  • @nirmithjainresearchassista849

    thanks a lot

  • @mariapontonglang6658
    @mariapontonglang6658 3 роки тому

    Thank you!!!

  • @rafy-ivanmorales3077
    @rafy-ivanmorales3077 2 роки тому

    I’m a new student and need help to do this project:
    I have a port scanner script it works properly, it works in Pycharm using python3.9.
    I have to make a file and I did make call (Example.txt)
    On this file, I have to do this:
    3. If the Ports is open, it should create a file and add an entry for port number
    4. In case of any exception for instance “host is not available”, “host name could not be resolved” or
    due to any other error, you need to write that exception into the same file.
    I’m not asking for you to do the project for me, I'm only asking ware I need to work or used in my script to accomplish this because it is my first time doing this and working with python too, and I have been struggling with this part one very bad. I can even send you the code, so you can look and only tell me what I’m doing bad, is not working.

  • @user-ev2oe8lc1i
    @user-ev2oe8lc1i 8 місяців тому

    thanks a lot !

  • @annahari610
    @annahari610 2 роки тому

    how to plot a hyperbola and ellipse

  • @spass526
    @spass526 3 роки тому

    Thanks for the video. But it's too small.

  • @flexer7822
    @flexer7822 3 роки тому

    you show how to plot a particular function, but i want to plot any function, how i solve that?
    for example: '2*x**2 + x'

  • @sayanjitb
    @sayanjitb 3 роки тому +1

    how can I plot this one: [X^(2) - (Y+ (X - Y^(2/3))^(2))=0] ? Because I can not seperate here X and Y values.

    • @aritryapaul6449
      @aritryapaul6449 2 роки тому

      its a multivariable function.so you need to define this as a function and plot this in 3d.the 3d plot is different from 2d plot.

  • @robertocaesar
    @robertocaesar 2 роки тому +1

    I know you have good content. But you must know that your video is unwatchable in a Cellphone.
    Which cut a great deal of watchers that get this on the fly. :-(

  • @andreaprado112
    @andreaprado112 10 місяців тому

    Thank you so much!!!!! You saved me!!!❤ subscribed 🥹