读取文本文件movies_revenue_starring_1950_2010.txt, 首先按照电影title降序排序,然后分别可视化电影的revenue Starring Actors Popularity 的值,每幅图均包括图例、图标题,x轴刻度值为电影title且斜45°显示(为了显示美观,可以将电影title每隔若干个抽样显示),每幅图曲线颜色分别为红色、绿色;每幅图分别保存为png图片保存,分辨率为400 dpi,png图片命名分别为movies_revenue_1950_2010.png、movies_ starpopularity_ 1950 2010.png
时间: 2023-12-14 12:36:19 浏览: 64
以下是Python代码实现:
``` python
import pandas as pd
import matplotlib.pyplot as plt
# 读取数据
data = pd.read_csv("movies_revenue_starring_1950_2010.txt", sep="\t")
# 按照电影title降序排序
data = data.sort_values(by="Title", ascending=False)
# 可视化电影的revenue
plt.figure(figsize=(16, 8))
plt.plot(data["Title"][::10], data["Revenue"][::10], color="red", label="Revenue")
plt.xticks(rotation=45, ha="right")
plt.legend()
plt.title("Revenue of Movies from 1950 to 2010")
plt.savefig("movies_revenue_1950_2010.png", dpi=400)
# 可视化电影的Starring Actors Popularity
plt.figure(figsize=(16, 8))
plt.plot(data["Title"][::10], data["Starpopularity"][::10], color="green", label="Starring Actors Popularity")
plt.xticks(rotation=45, ha="right")
plt.legend()
plt.title("Starring Actors Popularity of Movies from 1950 to 2010")
plt.savefig("movies_starpopularity_1950_2010.png", dpi=400)
```
该代码会生成两个png图片,分别为movies_revenue_1950_2010.png和movies_starpopularity_1950_2010.png,保存在当前工作目录下。
阅读全文