In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly shows you "how to create a scatter chart in Matplotlib", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "how to create a scatter chart in Matplotlib" this article.
Background introduction
Scatter plots are ideal for determining whether two sets of data are related. If there is a correlation, the scatter chart allows us to detect these trends. The idea of a scatter chart is usually to compare two variables. Let's get started.
Getting started example
First, let's take a look at the basic scatter plot code:
From matplotlib import pyplot as plt from matplotlib import font_manager# sets chart style plt.style.use ('seaborn') # x-axis data list x = [5pyrone 7pyrone # x-axis data list x = [5pyrone 7pyrone # x-axis data list x = [7pyrone 7pyrone # x-axis data list x = [5phir 7pyrone # x-axis data list x = [5pyrrine 7pyrus 8pje 4pje 4pje 4pje 5pje 6pje 7pje 5pje 6pje 7pr 7pje 5pje 4pje 7pje 5pje 2pje 4pje 4pje 7pje 4pje x = [5pje 7pr 7pr 8pr 4pje 4pr 7pje 5pje 5pje 4pje 4pje 7pr 5pr 5pje 7pje 4pje 4pje 4pr 4pr 4pr 5pr 4pr 4pr 4pr 4e] y = [7pr 4pr 4pr 4pr x 7 scatter 5] # use scatter () to create a scatter chart # s: scatter size # c: scatter color # cmap:Clolormap color mapping name # use plt.scatter only when c is a floating-point array (xmemymens100recovericcolorsmappings grey, edgecolor='black',lineWidth=1 Alpha=0.75) zh_font = font_manager.\ FontProperties (fname='C:\\ Windows\\ Fonts\\ msyh.ttf') # add a color bar to the drawing cbar = plt.colorbar () cbar.set_label ('Legend', fontproperties=zh_font) plt.tight_layout () plt.show ()
Running result:
Comprehensive example
Next, let's do a scatter distribution of popular videos. Reading from a locally prepared data.csv file includes three items: the number of videos played per behavior, the number of likes (likes), and the ratio of likes / dislikes:
Let's show it in the form of a scatter plot:
Import pandas as pdfrom matplotlib import pyplot as pltfrom matplotlib import font_manager# sets chart style plt.style.use ('seaborn') # reads data # number of playbacks and likes Data = pd.read_csv ('data.csv') view_count = data [' view_count'] likes = data ['likes'] ratio = data [' ratio'] # call the scatter chart method plt.scatter (view_count, likes, c=ratio, cmap='summer', edgecolor='black', linewidth=1) Alpha=0.75) zh_font = font_manager.\ FontProperties (fname='C:\\ Windows\\ Fonts\\ msyh.ttf') cbar = plt.colorbar () cbar.set_label ('like / dislike ratio', fontproperties=zh_font) # x and y display plt.xscale ('log') plt.yscale (' log') plt.title ('popular website videos', fontproperties=zh_font) plt.xlabel ('views', fontproperties=zh_font) plt.ylabel ('Total likes') in log Fontproperties=zh_font) plt.tight_layout () plt.show ()
Running result:
The above is all the content of the article "how to create a scatter chart in Matplotlib". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.