数据分析第四节课Matplotlib作业

练习一:
电影数据如下:
movies_name = [“变身特工”,“美丽人生”,“鲨海逃生”,“熊出没·狂野大陆”]
day_12 = [2358,399,2358,362]
day_13 = [12357,156,2045,168]
day_14 = [15746,312,4497,319]
需求:
• 直观体现出不同电影近三天的票房的对比情况

"""
电影数据如下:
movies_name = ["变身特工","美丽人生","鲨海逃生","熊出没·狂野大陆"]
day_12 = [2358,399,2358,362]
day_13 = [12357,156,2045,168]
day_14 = [15746,312,4497,319]
需求:
• 直观体现出不同电影近三天的票房的对比情况
"""
import matplotlib.pyplot as plt
# 字体
plt.rcParams['font.sans-serif'] = ['Heiti TC']

plt.figure(figsize=(20, 8), dpi=100)

movies_name = ["变身特工","美丽人生","鲨海逃生","熊出没·狂野大陆"]
day_12 = [2358,399,2358,362]
day_13 = [12357,156,2045,168]
day_14 = [15746,312,4497,319]

x = range(len(movies_name))
plt.bar([i-0.2 for i in x], day_12, width=0.2, color='r', label = "day_12")
plt.bar(x, day_13, width=0.2, color='g', label = "day_13")
plt.bar([i+0.2 for i in x], day_14, width=0.2, color='b', label = "day_14")

plt.xlabel("电影名称")
plt.ylabel("各日电影数据")

# 显示x轴中文
plt.xticks(x, movies_name)

# 注释函数
def auto_label(x_po, y_po):
    for x_i, y_i in list(zip(x_po, y_po)):
        plt.annotate(f"{y_i}", xy=(x_i, y_i))

auto_label([i-0.2 for i in x], day_12)
auto_label(x, day_13)
auto_label([i+0.2 for i in x], day_14)

# 添加图例
plt.legend(loc = "best")

plt.savefig("电影票房对比.jpg")
plt.show()

在这里插入图片描述

练习二:
绘制班级的身高分布图形
height = [160,163,175,180,176,177,168,189,188,177,174,170,173,181]

"""
绘制班级的身高分布图形
height = [160,163,175,180,176,177,168,189,188,177,174,170,173,181]
"""
import matplotlib.pyplot as plt
# 字体
plt.rcParams['font.sans-serif'] = ['Heiti TC']
plt.figure(figsize=(13, 8), dpi=100)
height = [160,163,175,180,176,177,168,189,188,177,174,170,173,181]

# 组距
bin = 5

# 组数
groups = int(max(height) - min(height) / bin)
plt.hist(height, bin, rwidth=0.5)

# 指定刻度范围
plt.xticks(list(range(min(height), max(height)))[::5])

plt.xlabel("身高分布")
plt.ylabel("人员个数")

plt.savefig("身高分布图.jpg")
plt.show()

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值