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() - วิทยาศาสตร์และเทคโนโลยี
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
THAAAAAAAAAANK YOU so much =D
I've been looking for such a straight and simple tutorial for so long!
Hey, thanks a lot for showing this, very clear and easy to follow. Liked
Excellent content. Subscribed. Commenting for the algorithms.
Awesome! Thanks for the clear guide of how to use this matplotlib tool!
Very good video!
Thank you so much!! Needed to do something similar for an assignment, this really helped!!
Please include in your title "Spyder". It will help in the search! :)
Thank you very much for this Mister.
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)
Worth watching
awesome. straight, easy, clear -> perfect!
Very helpful!
What code editor are you using?
He is using Spyder. It is a programming platform designed to be used by scientists.
thanks a lot
Very good
Thank you!!!
very useful for beginner, thank you;
thanks a lot !
these math ones are important... algorithms, plotting, more, please...
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.
how about if dont know about values of a,b,c and need input ourself, then how to plot the graph
what is that code editor?
Thanks for the videos, could you zoom in on the screen to better see the letter of the code? Thank you
The full script is also written in the video description
Can you please use light mode?
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??
You should zoom in the coding part..cant see properly,
Thanks for the video. But it's too small.
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.
how to plot a hyperbola and ellipse
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. :-(
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'
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.
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.
Thank you so much!!!!! You saved me!!!❤ subscribed 🥹