Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Python for data Visualization

2025-01-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces "how to use Python for data visualization". In daily operation, I believe many people have doubts about how to use Python for data visualization. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the questions of "how to use Python for data visualization". Next, please follow the editor to study!

In data analysis, it is often necessary to visualize the data in order to facilitate our understanding and understanding of the data.

A brief introduction to 0Jet Matplotlib

Matplotlib is a visualization toolkit that allows us to use Python to visualize data.

Here are some official resources you can click to see:

Matplotlib installation

Matplotlib user's Manual

Summary of Matplotlib functions

Matplotlib module index

Matplotlib sample library

Download Matplotlib sample

Python code

Jupyter notebooks

Many of the more advanced drawing libraries are also based on Matplotlib, such as seaborn,HoloViews,ggplot.

When using Matplotlib, you often need to use the pyplot module, which is introduced with the following code:

Import matplotlib.pyplot as plt

Below, plt is used to refer to pyplot.

Description: here we only introduce a few simple pictures, more other pictures, you can see the official manual. Each of the following functions describes only the simplest usage, and more parameters can be found in the manual.

1, scatter plot

The plt.scatter function is used to draw a scatter chart. Function prototype:

Scatter (x, y, s = None, c = None, marker = None)

Parameter meaning:

X, y: represent the horizontal and vertical coordinates of the point, respectively. X, y can be a single point coordinate or a set of point coordinates.

S: represents the size of the point.

C: represents the color of the point.

Marker: indicates the shape of the point. Optional values can be found here, for example, the values of marker are x, o, s, etc.

In the following code, three points are drawn:

# the coordinates of the three points are: # (2,5) # (3Power6) # (3,5) plt.scatter ([2,3,3], [5,6,5], marker='o') plt.show () # display figure

The scatter plot is as follows:

2, line chart

The plt.plot function is used to draw a line chart. Function prototype:

Plot (x, y)

The parameter xrem y represents the horizontal and vertical coordinates of the point, which is generally a set of point coordinates.

For example, the following table represents the results of five math tests:

Number of times 12345, score 8978927986.

Draw the above table data into a line chart, the code is as follows:

X = [1,2,3,4,5] y = [89,78,92,79,86] plt.plot (x, y) plt.show ()

The line chart drawn is as follows:

3, histogram

Histograms are used to describe the distribution of data.

The plt.hist function is used to draw a histogram. Function prototype:

Plt.hist (x, bins=None)

Parameter x is an one-dimensional array, bins can be understood as the number of rectangles, the default is 10.

If the following is the result of a math test, there are 50 students in the class:

Draw the scores of all students into a histogram, the code is as follows:

Scores = [96, 89, 95, 91, 94, 95, 92, 98, 95, 93, 93, 96, 94, 94, 98, 92, 88, 88, 88, 98, 84, 89, 87, 84, 94, 82, 83, 95, 93, 79, 84, 91, 81, 89, 77, 77, 70, 66, 93, 90, 87, 79, 83, 86, 90, 93, 79,] plt.hist (scores) plt.show ()

The histogram drawn is as follows, the Abscissa is the score range, and the vertical coordinate is the number of people:

Through the histogram, the number of people in each score range can be seen intuitively.

4, bar chart

The plt.bar function is used to draw a bar chart. Function prototype:

Plt.bar (x, y, width = 0.8)

The parameters x and y are all an array, x is Abscissa, indicating the data category, and y is ordinate, indicating the frequency of each category. The parameter width indicates the width of the strip.

For example, the following table shows the scores of each subject in a student's mid-term exam:

We draw the student's report card into a bar chart, the code is as follows:

# each subject is represented by letters subjects = ['subjects,' scores, 'scores,' subjects, scores) plt.show ()

The bar chart drawn is as follows:

5, pie chart

Pie charts are often used to show the proportion of individuals in the total.

The plt.pie function is used to draw a pie chart. Function prototype:

Plt.pie (x, labels=None)

The parameter x is an array that represents a set of data, and labels is used to describe the meaning of each data.

For example, the following table shows the quarterly income of a company in a given year:

We can use a pie chart to analyze each quarter as a percentage of annual revenue, as follows:

# indicates that every quarter quarters = ['1percent,' 2percent, '3percent,' 4'] incomes = [56,89,75,91] plt.pie (incomes, labels=quarters) plt.show ()

The pie chart is as follows:

At this point, the study on "how to use Python for data visualization" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report