Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to use Matplotlib to draw in Python

Shulou Source: shulou.com Published: 2022-06-02 05:53:45 11月10日 Update

How to use Matplotlib drawing in Python, in view of this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.

Simple drawing

Simple drawing is included in the matplotlib.pyplot package. It is important to keep in mind that subsequent functions change the current drawing. Eventually, we will save the drawing to a file or display it using the show function. However, if we are using IPython running on the Qt or Wx backend, the graph will be updated interactively without waiting for the result of the show function. This is similar to the way text is output on the screen and can be printed continuously.

PS: if you need Python learning materials, you can add the group below to go to the free administrator to get it.

Hands-on practice: drawing polynomial functions

To illustrate the principle of drawing, let's draw a picture of a polynomial function. We will use NumPy's polynomial function poly1d to create a polynomial.

The main results are as follows: (1) the natural number sequence is used as the coefficient of the polynomial and the poly1d function is used to create the polynomial.

Func = np.poly1d (np.array ([1,2,3,4]) .astype (float))

(2) use the linspace function of NumPy to create values on the x-axis, producing 30 uniformly distributed values between-10 and 10.

X = np.linspace (- 10,10,30)

(3) calculate the value of the polynomial we created in the first step.

Y = func (x)

(4) call the plot function, which does not immediately display the function image.

Plt.plot (x, y)

(5) use the xlabel function to add the x-axis label.

Plt.xlabel ('x')

(6) use the ylabel function to add the y-axis label.

Plt.ylabel ('y (x)')

(7) call the show function to display the function image.

Plt.show () on how to use Matplotlib in Python drawing questions to share here, I hope the above content can be of some help to you, if you still have a lot of doubts have not been solved, you can follow the industry information channel to learn more related knowledge.

Tags: Functions drawings polynomials images questions guys buddies more tags help answers easy continuous simple continuous interactive content function principle Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Linux OPPO Reno Redmi MariaDB