Home  >  Article  >  Backend Development  >  How to draw the curve of a function in python

How to draw the curve of a function in python

尚
Original
2019-07-06 13:27:5410944browse

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).

How to draw the curve of a function in python

Enter the following code to import the function library we use.

>>> import numpy as np
>>> import matplotlib.pyplot as plt

How to draw the curve of a function in python

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);

How to draw the curve of a function in python

Enter the following command and we can insert the card to the function we want to draw.

plt.plot(x,y)

How to draw the curve of a function in python

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()

How to draw the curve of a function in python

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn