简体   繁体   English

Python中的直方图数据可视化(使用matplotlib)

[英]Histogram Data Visualization in Python (using matplotlib)

I'm pretty new to StackOverflow.我对 StackOverflow 很陌生。 Recently I've been doing a web data scraping python project where I use bs4 to scrape the titles, publication dates, and author names from a website and store them into lists.最近我一直在做一个网络数据抓取 python 项目,我使用 bs4 从网站上抓取标题、出版日期和作者姓名,并将它们存储到列表中。 Now I want to do some visualization using matplotlib to generate some visuals so I can put them on a website and host the website using aws.现在我想使用 matplotlib 进行一些可视化以生成一些视觉效果,以便我可以将它们放在网站上并使用 aws 托管该网站。

The problem is that I have the date but I'm not sure how to use matplotlib for example, generate a histogram of # of articles being published each year, or names of the author who appear in most articles.问题是我有日期,但我不确定如何使用 matplotlib,例如,生成每年发表的文章数量的直方图,或大多数文章中出现的作者姓名。 Here are the lists I have rn:以下是我的列表:

#print(year_list)
# print(id_list)
# print(title_list)
# print(author_list)
# print(publication_date_list)
# print(abstract_list)

And snippets of printed year_list:以及打印的 year_list 片段:

['2019', '2019', '2019', '2019', '2019', '2019', '2019', '2019', '2019', '2019', '2019', '2018', '2018', '2018',...]

Any suggestions about how I can use tools to visualize these lists?关于如何使用工具来可视化这些列表的任何建议?

I mean, shouldn't you just be able to copy & paste an example like that on pythonspot.com and simply replace its data with your data?我的意思是,您不应该只是能够在pythonspot.com上复制和粘贴这样的示例,然后简单地将其数据替换为您的数据吗?

Edit: Replacing x in the example with your snippet from year_list produced this histogram:编辑:将示例中的 x 替换为您来自 year_list 的代码段,生成了此直方图: year_list 直方图

Edit 2: Just in case, the code is this:编辑 2:以防万一,代码是这样的:

import matplotlib.mlab as mlab
import matplotlib.pyplot as plt

x = ['2019', '2019', '2019', '2019', '2019', '2019', '2019', '2019', '2019', '2019', '2019', '2018', '2018', '2018']

num_bins = 5

n, bins, patches = plt.hist(x, num_bins, facecolor='blue', alpha=0.5)

plt.show()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM