Home > Article > Backend Development > How to draw the curve of a function in python
Python is a commonly used computer programming language. The matplotlib library can be used to draw the curve of our function.
Open the Python shell interface, as shown in the figure. (Note that we need to have the matplotlib library package installed).
Enter the following code to import the function library we use.
>>> import numpy as np >>> import matplotlib.pyplot as plt
Generate the data of the function we want to draw, taking the sin function as an example, the code is as follows.
>>> x=np.arange(0,5,0.1); >>> y=np.sin(x);
Enter the following command and we can insert the card to the function we want to draw.
plt.plot(x,y)
We can see the image we want to draw.
After using the code just now, the picture below may not be displayed. Then enter the following code:
plt.show()
For more Python-related technical articles, please visit the Python Tutorial column to learn!
The above is the detailed content of How to draw the curve of a function in python. For more information, please follow other related articles on the PHP Chinese website!