You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
956 B

import pandas as pd
import matplotlib.pyplot as plt
# 加载数据
df = pd.read_csv('/mnt/豆瓣电影_20250510_173909.csv')
# 统计不同导演的作品数量
director_counts = df['导演'].value_counts()
# 找出作品数量前五的导演
top_five_directors = director_counts.nlargest(5, keep='all')
# 设置图片清晰度
plt.rcParams['figure.dpi'] = 300
# 设置中文字体
plt.rcParams['font.sans-serif'] = ['WenQuanYi Zen Hei']
# 绘制柱状图
plt.figure(figsize=(10, 6))
bars = top_five_directors.plot(kind='bar')
# 添加数据标签
for bar in bars.patches:
height = bar.get_height()
plt.text(bar.get_x() + bar.get_width() / 2, height, str(int(height)), ha='center', va='bottom')
# 设置图表标题和坐标轴标签
plt.title('作品数量前五的导演')
plt.xlabel('导演')
plt.ylabel('作品数量')
plt.xticks(rotation=45)
# 显示图形
plt.show()
print('作品数量前五的导演:')
print(top_five_directors)