Python visualization is simple, but can you? Python draws pie charts, epigraphs and bubble charts, one article teaches you! ! !

The matplotlib library is the most classic and most commonly used library for Python data visualization. Mastering it is equivalent to learning Python data visualization. Today, let’s talk about how Python draws pie charts, epigraphs and Bubble chart

Alright, stop talking nonsense, let's get started!

Use the pie() function of the matplotlib library to draw a pie chart

The function of the pie() function is to give it some data and the percentage, and it can return you a classic pie chart. Let’s talk about its syntax first:

matplotlib.pie(x)

The parameter x represents the percentage of different categories of qualitative data!

Well, in order to give everyone a deeper understanding, let's give a "chestnut":

The above box is the pie() function we called. Let's run it to see the effect!

Run the above command to output the following effect picture:

Use the polar() function of the matplotlib library to draw the polar diagram

The role of the polar() function is to draw a line graph on the polar coordinate axis. At this point, friends may ask again, what is the polar coordinate? Regarding the problem of polar coordinates, this is a mathematical problem. If you don’t understand, you can search it online. I won’t explain it in this editor, because I may not be able to explain it clearly!

Okay, let's take a look at the syntax format of the polar() function:

matplotlib.polar(theta, r)

The parameter theta represents the angle between the polyline where each mark is located and the polar diameter, and the r parameter represents the distance from each mark to the origin. It may be a bit difficult to understand the epigraph. You only need to call the polar() function. it is okay!

Well, let's take a "chestnut" to illustrate how to call the polar() function:

The above box is the polar() function we called. Let’s run it to see the effect:

Run the above command and output the epipolar chart:

Use the scatter() function of the matplotlib library to draw a bubble chart

The role of the scatter() function is to use two-dimensional data to display three-dimensional data with the help of bubble size. Let’s first talk about its grammatical format:

matplotlib.scatter(x, y, s, c, cmap)

Among them, the parameter x represents the value on the x-axis, the parameter y represents the value on the y-axis, the parameter s represents the size of the scatter mark, the parameter c represents the color of the scatter mark, and the cmap parameter represents the mapping of floating point numbers. Color mapping table into colors!

Well, in order to better understand the bubble chart, let’s give a "chestnut":

Similarly, the scatter() function is called in the box above:

Run the above command to output the bubble chart:

What we talked about above is about the knowledge related to drawing pie charts, epigraphs and bubble charts in Python data visualization. Although the epigraphs and bubble charts are a bit difficult to understand, the charts drawn are quite beautiful. I hope that when you visualize Python data in the future, these three drawing methods can bring brilliant performance to your work!

Finally, I hope you all learn how to call the pie(), polar() and scatter() functions in the matplotlib library. Well, let’s talk about it today, see you next time! [Goodbye]

Python learning exchange group , welcome all friends to exchange and learn.

Guess you like

Origin blog.csdn.net/Python_xiaobang/article/details/112322040