How to: Plot a Function in Python

Поделиться
HTML-код
  • Опубликовано: 7 июл 2024
  • Learn how to define a function and plot it in Python.
    Script can be found here: www.hageslab.com/Resources.ht...
    Here we are using "Spyder" IDE with the numpy and matplotlib libraries
    Useful resources:
    matplotlib.org/tutorials/text...
    matplotlib.org/
    matplotlib.org/3.3.3/api/_as_...
    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()
  • НаукаНаука

Комментарии • 36

  • @maramarsu8204
    @maramarsu8204 2 года назад +10

    You could be a RUclips 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 RUclips algorithm will pick you up

  • @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!

  • @k-xxy8308
    @k-xxy8308 2 года назад +1

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

  • @simone9740
    @simone9740 3 года назад +6

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

  • @shinyshadow1
    @shinyshadow1 3 года назад +1

    awesome. straight, easy, clear -> perfect!

  • @iriisnes
    @iriisnes 2 года назад +1

    Excellent content. Subscribed. Commenting for the algorithms.

  • @najeebzakariya2346
    @najeebzakariya2346 2 года назад

    Thank you very much for this Mister.

  • @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)

  • @junaid2773
    @junaid2773 2 года назад

    Very helpful!

  • @mashedpotato9628
    @mashedpotato9628 Год назад +1

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

  • @anubhavrajyan7963
    @anubhavrajyan7963 2 года назад

    Worth watching

  • @mariapontonglang6658
    @mariapontonglang6658 2 года назад

    Thank you!!!

  • @cristianortiz3349
    @cristianortiz3349 3 года назад

    Very good

  • @chewchengkai2769
    @chewchengkai2769 3 года назад

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

  • @RakeshKumar-he6ek
    @RakeshKumar-he6ek 2 года назад

    very useful for beginner, thank you;

  • @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??

  • @bobcrane4801
    @bobcrane4801 Год назад

    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.

  • @nirmithjainresearchassista849
    @nirmithjainresearchassista849 11 месяцев назад

    thanks a lot

  • @pratyushpro9060
    @pratyushpro9060 2 года назад +1

    what is that code editor?

  • @coryreedrobbins
    @coryreedrobbins 3 года назад +2

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

  • @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.

  • @arpitakundu7847
    @arpitakundu7847 5 месяцев назад

    Can you please use light mode?

  • @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.

  • @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

  • @spass526
    @spass526 3 года назад

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

  • @user-ev2oe8lc1i
    @user-ev2oe8lc1i 7 месяцев назад

    thanks a lot !

  • @shibushil4164
    @shibushil4164 2 года назад

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

  • @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'

  • @annahari610
    @annahari610 2 года назад

    how to plot a hyperbola and ellipse

  • @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 9 месяцев назад

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