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 do Pandas drawing in Python

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

Share

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

This article will explain in detail how to do Pandas drawing in Python. The content of the article is of high quality, so the editor shares it for you as a reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.

Pandas is a very common data processing tool in Python, and it is very convenient to use. Because it is based on the NumPy array structure, many of its operations are written by NumPy or Pandas's own extension modules, which are written in Cython, compiled to C, and executed on C, thus ensuring processing speed. However, our focus today is not on its processing speed, but on the powerful and convenient drawing capabilities produced by its cooperation with matplotlib.

How strong is it? Let's experience it.

1. Create data

You can easily create data with pandas, so now let's create a pandas DataFrame with 5 columns and 1000 rows:

A1 and a2: random samples taken from a normal (Gaussian) distribution.

A random integer in a3purl 0 to 4.

The logarithmic scales of Y1RV 0 to 1 are evenly distributed.

A random integer in y2purl 0 to 1.

Generate the data shown below, which will be used in subsequent experiments:

two。 Draw an image

The Pandas drawing function returns an axis of matplotlib (Axes), so we can customize what we need to draw on it. For example, draw a vertical and parallel line. This will be very good for us:

1. Draw the average line

two。 Mark key points

We can also customize how many tables are displayed on a graph:

3. Draw a histogram

Pandas allows us to compare the shapes of two shapes in a very simple way:

It also allows multiple maps to be drawn:

Of course, the line chart is also fine:

4. Linear fitting

You think it's over? No, no! Pandas can also be used for fitting, so let's use pandas to find the line closest to the following image:

The least square method is used to calculate the shortest distance of the line:

Draw y and fit a straight line according to the result of the least square:

If you like today's Python tutorial, please continue to follow the Python practical treasure book, if it is helpful to you, please click on a like / read below, you can leave a message below if you have any questions, and we will answer them patiently!

On how to carry out Pandas drawing in Python to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

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