From 6bcb88f42d4e9a6b84e1d27c679ae701e3085452 Mon Sep 17 00:00:00 2001 From: ptlqmxye5 <2946992557@qq.com> Date: Tue, 17 Sep 2024 22:03:19 +0800 Subject: [PATCH] ADD pie_chart file --- pie_chart.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 pie_chart.py diff --git a/pie_chart.py b/pie_chart.py new file mode 100644 index 0000000..b2e9b1a --- /dev/null +++ b/pie_chart.py @@ -0,0 +1,19 @@ +import pandas as pd +import matplotlib.pyplot as plt +import matplotlib + +# 设置默认字体以支持中文 +matplotlib.rcParams['font.sans-serif'] = ['Microsoft YaHei'] + +# 读取 Excel 文件 +df = pd.read_excel('danmu_statistics.xlsx', sheet_name='AI 技术关键词') + +# 数据在名为 '关键词' 和 '出现次数' 的列中 +categories = df['关键词'] +values = df['出现次数'] + +# 绘制饼状图 +plt.figure(figsize=(8, 6)) +plt.pie(values, labels=categories, autopct='%1.1f%%', startangle=140) +plt.title('AI 技术各关键词占比') +plt.show()