import matplotlib.pyplot as plt # 1.数据准备 # 房屋面积数据 movie_names = ["雷神3","正义联盟","A","B","C","D","E"] # 房屋价格数据 tickets = [73853, 57767,22354,15969,14839,8716,52222] # 2.创建画布 plt.figure(figsize=(10, 4), dpi=80) # 3.绘制图像 x_ticks = range(len(movie_names)) plt.bar(x_ticks, tickets, color=["b","r","g","y","c","m","y"]) # 修改x刻度 plt.xticks(x_ticks, movie_names) # 添加标题 plt.title("电影票房收入对比") # 添加网格 plt.grid(linestyle="--", alpha=0.5) # 显示图像支持中文 plt.rcParams['font.sans-serif'] = ['SimHei'] # 用来正常显示中文标签 plt.rcParams['axes.unicode_minus'] = False # 用来正常显示负号 plt.show()
import matplotlib.pyplot as plt # 1.数据准备 movie_names = ["雷神3","正义联盟","幻影车神","复仇之联盟"] first_day = [10587.6, 10030.1,10062.5, 1275.7] first_week = [30587.6, 20043.9, 30062.5, 1275.7] # 2.创建画布 plt.figure(figsize=(10, 4), dpi=80) # 3.绘制图像 plt.bar(range(4), first_day, width=0.2, label="首日票房") plt.bar([i+0.2 for i in range(4)], first_week, width=0.2, label="首周票房") # 显示图列 plt.legend() # 修改x刻度 plt.xticks([i+0.2 for i in range(4)], movie_names) # # 添加标题 plt.title("电影票房收入对比") # # 添加网格 plt.grid(linestyle="--", alpha=0.5) # 显示图像支持中文 plt.rcParams['font.sans-serif'] = ['SimHei'] # 用来正常显示中文标签 plt.rcParams['axes.unicode_minus'] = False # 用来正常显示负号 plt.show()