How to: Plot a Function in Python

แชร์
ฝัง
  • เผยแพร่เมื่อ 16 ส.ค. 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 TH-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 TH-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

  • @iriisnes
    @iriisnes 2 ปีที่แล้ว +1

    Excellent content. Subscribed. Commenting for the algorithms.

  • @zjason7582
    @zjason7582 ปีที่แล้ว

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

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

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

  • @anubhavrajyan7963
    @anubhavrajyan7963 2 ปีที่แล้ว

    Worth watching

  • @shinyshadow1
    @shinyshadow1 3 ปีที่แล้ว +1

    awesome. straight, easy, clear -> perfect!

  • @junaid2773
    @junaid2773 2 ปีที่แล้ว

    Very helpful!

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

  • @nirmithjainresearchassista849
    @nirmithjainresearchassista849 ปีที่แล้ว

    thanks a lot

  • @cristianortiz3349
    @cristianortiz3349 3 ปีที่แล้ว

    Very good

  • @mariapontonglang6658
    @mariapontonglang6658 3 ปีที่แล้ว

    Thank you!!!

  • @RakeshKumar-he6ek
    @RakeshKumar-he6ek 2 ปีที่แล้ว

    very useful for beginner, thank you;

  • @user-ev2oe8lc1i
    @user-ev2oe8lc1i 8 หลายเดือนก่อน

    thanks a lot !

  • @coryreedrobbins
    @coryreedrobbins 3 ปีที่แล้ว +2

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

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

  • @chewchengkai2769
    @chewchengkai2769 3 ปีที่แล้ว

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

  • @pratyushpro9060
    @pratyushpro9060 3 ปีที่แล้ว +1

    what is that code editor?

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

  • @arpitakundu7847
    @arpitakundu7847 6 หลายเดือนก่อน

    Can you please use light mode?

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

  • @shibushil4164
    @shibushil4164 2 ปีที่แล้ว

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

  • @spass526
    @spass526 3 ปีที่แล้ว

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

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

  • @annahari610
    @annahari610 2 ปีที่แล้ว

    how to plot a hyperbola and ellipse

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

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

  • @andreaprado112
    @andreaprado112 10 หลายเดือนก่อน

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