Get the App
SLTechnology News&Howtos  ›  Development  › 

Example Analysis of drawing function with python pyplot

Shulou Source: shulou.com Published: 2022-06-02 21:27:53 10月02日 Update

In this issue, the editor will bring you an example analysis of using python pyplot to draw functions. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.

Brief introduction

This paper mainly introduces how to draw function diagram through pyplot. The main drawing functions are as follows:-unary quadratic function-exponential function-natural logarithmic function-sine function

Unary first order function

Code

Import matplotlib.pyplot as pltimport numpy as npx = np.arange (0,10,0.1) y = x * 2plt.title ("unary linear function") plt.plot (x, y) plt.show ()

Unary quadratic function

Code

Import matplotlib.pyplot as pltimport numpy as npx = np.arange (- 10,10,0.1) y = X-ray 2 + 2x + 1plt.title ("quadratic function of one variable") plt.plot (x, y) plt.show ()

Exponential function

Code

Import matplotlib.pyplot as pltimport numpy as npimport mathx = np.arange (0,10,0.1) y = 2**xplt.title ("exponential function") plt.plot (x, y) plt.show ()

Natural logarithmic function

Code

Import matplotlib.pyplot as pltimport numpy as npimport mathx = np.arange (0,10,0.1) e = math.ey = e**xplt.title ("natural logarithmic function") plt.plot (x, y) plt.show ()

Sinusoidal function

Code

Import matplotlib.pyplot as pltimport numpy as np# linspace the first parameter sequence start value, the second parameter sequence end value, the third parameter is the sample number default 50x = np.linspace (- np.pi, np.pi, 100) y = np.sin (x) plt.title ("sine function") plt.plot (x, y) plt.show ()

The above is Xiaobian for you to share the use of python pyplot drawing function analysis of the example, if there happens to be a similar doubt, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.

Tags: Function code analysis exponential function primary function parameter logarithm index sine nature example case analysis content sequence three professional small and medium rich in content that is the article Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Redmi Shulou Tech Info macOS Microsoft