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 draw Matplotlib scatter Diagram by Python

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly explains "Python how to draw Matplotlib scatter chart", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Now let the editor to take you to learn "Python how to draw Matplotlib scatter chart"!

Use the plt.plot method:

In the previous article Matplotlib line chart drawing for Python data analysis, we introduced that we can use the plt.plot () method to draw a line chart, and this method can also draw a scatter chart, as follows:

Import randomx = range (15) y = [I + random.randint (- 2pm 2) for i in x] plt.plot (x, y, "o") plt.show ()

The output is as follows:

Because the plot method draws a line chart by default, plt.plot (x, y) is equivalent to plt.plot (x, y, "-"), and the third parameter "-" means to use lines to connect coordinate points, if points are used. Or circle o to connect these 10 points together, and what is presented is a scatter plot.

In addition to -,., o, there are other types, such as x, +, v, ^, etc., which can be explored on their own.

Use the plt.scatter method:

Matplotlib also provides another powerful method, plt.scatter (), in the following format:

Plt.scatter (x, y, s=None, c=None, marker=None,)

The main parameters in the function are described as follows:

X, y: represent the data corresponding to the x-axis and y-axis, respectively, and receive the list type parameters

S: represents the size of the point. The default is 20. It can be a character or list. When it is a list, each element of the list represents the size of the corresponding point.

C: represents the color of the point, which can be the character or list. When it is a list, each element of the list represents the color of the corresponding point.

Marker: indicates the type of point drawn. Default small circle o

Alpha: indicates the transparency of the point and receives the decimal between 0: 1

For example:

Import randomx = range (15) y = [I + random.randint (- 2pm 2) for i in x] plt.scatter (x, y, marker= "v") plt.show ()

The output is as follows:

At this point, I believe you have a deeper understanding of "Python how to draw Matplotlib scatter chart". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

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

Development

Wechat

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

12
Report