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 read csv File and generate Bar Chart by Matplotlib

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

Share

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

Editor to share with you how Matplotlib reads csv files to generate bar charts, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

Learn to use Matplotlib to create bar charts, it is very suitable to show the total value of each category to display data, will learn to load data from csv files, and the data will be displayed in a bar chart, csv file content for statistics more than 80,000 people in the daily work of the programming language, we will use graphics to show the most popular top 15 programming ranking chart.

Code actual combat

First of all, let's take a look at the contents of data.csv, which has two columns: the first column is the user's id, the second column is the programming language used and separated by commas, and some data screenshots are taken:

Next, let's code to show the chart:

Import pandas as pdfrom collections import Counterfrom matplotlib import pyplot as pltfrom matplotlib import font_manager

# set chart style plt.style.use ('fivethirtyeight') # here use pandas to read the csv file data = pd.read_csv (' data.csv')

Ids= data ['Responder_id'] langs = data [' LanguagesWorkedWith'] # defines a Counter# to calculate the total number of programming language categories language_counter = Counter () for lang in langs: language_counter.update (lang.split (';'))

Languages = [] popularity = []

# take the first 15 popular languages for item in language_counter.most_common (15): languages.append (item [0]) popularity.append (item [1])

# display languages.reverse () popularity.reverse () in reverse order # set the font of the chart zh_font = font_manager.FontProperties (fname='C:\\ Windows\\ Fonts\\ msyh.ttf') # use horizontal bar chart plt.barh (languages,popularity) plt.title ("most popular language ranking", fontproperties=zh_font) plt.xlabel ("number of users", fontproperties=zh_font) plt.tight_layout () plt.show ()

Running effect:

The above is all the contents of the article "how to read csv files to generate bar charts by 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.

Share To

Internet Technology

Wechat

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

12
Report