ADD file via upload
This commit is contained in:
parent
f8986515ae
commit
e7641da6e9
|
@ -0,0 +1,47 @@
|
|||
import matplotlib
|
||||
import pandas as pd
|
||||
from matplotlib import pyplot as plt
|
||||
matplotlib.use('agg')
|
||||
|
||||
dict_all=[]
|
||||
for i in range(1, 7):
|
||||
df = pd.read_excel(f'data{2017+i}.xlsx')
|
||||
specific_column = '语言'
|
||||
dict_year = df[specific_column].value_counts().to_dict()
|
||||
dict_top = dict(sorted(dict_year.items(), key=lambda item: item[1], reverse=True)[:10])
|
||||
dict_all.append(dict_top)
|
||||
|
||||
all_keys = set().union(*[d.keys() for d in dict_all])
|
||||
|
||||
# 绘制折线图
|
||||
fig, ax = plt.subplots(figsize=(10, 8))
|
||||
for key in all_keys:
|
||||
x = [1, 2, 3, 4, 5, 6]
|
||||
y = [d.get(key, None) for d in dict_all]
|
||||
ax.plot(x, y, marker='o', label=key)
|
||||
|
||||
ax.set_xticks(x)
|
||||
ax.set_xticklabels(['2018', '2019', '2020', '2021', '2022', '2023'])
|
||||
ax.set_xlabel('Year')
|
||||
ax.set_ylabel('utilization number')
|
||||
ax.set_title('Trends in the use of Language')
|
||||
plt.savefig('Trends in the use of Language.png')
|
||||
|
||||
# 创建一个新的图表,用于显示标签
|
||||
fig_legend = plt.figure(figsize=(6, 4))
|
||||
ax_legend = fig_legend.add_subplot(111)
|
||||
|
||||
# 存储所有键的集合
|
||||
all_keys = set().union(*[d.keys() for d in dict_all])
|
||||
|
||||
# 绘制标签
|
||||
for key in all_keys:
|
||||
ax_legend.plot([], [], label=key) # 添加一个空的 plot,仅用于显示标签
|
||||
|
||||
# 显示图例
|
||||
ax_legend.legend(loc='center', bbox_to_anchor=(0.5, 0.5))
|
||||
ax_legend.axis('off') # 关闭坐标轴
|
||||
|
||||
plt.savefig('Line_Language.png')
|
||||
# 显示图形
|
||||
plt.show()
|
Loading…
Reference in New Issue