第三节 matplotlib绘制条形图

from matplotlib import pyplot as plt
import matplotlib

# 设置字体大小
font = {'family':'MicroSoft YaHei',
        'weight':'bold',
        'size':8}
matplotlib.rc("font",**font)

a = ["战狼2", "哪吒之魔童降世", "流浪地球", "复仇者联盟4
终局之战", "红海行动", "美人鱼", "唐人街探案2"]
b = [56.39, 49.34, 46.18, 42.05, 36.22, 33.9, 33.71]
x = range(len(a))

fig = plt.figure(figsize=(10, 5))

# width控制条形图的粗细
# plt.bar(x, b, width=0.3)

# 横着的条形图,height控制条形图的粗细
plt.barh(x, b, height=0.4)

# plt.xticks(x, labels= [i for i in a], rotation=30)
# plt.yticks(range(0, 60,3))
plt.yticks(x, labels= [i for i in a])
plt.xticks(range(0, 60,3))

# plt.xlabel("电影名称")
# plt.ylabel("票房/亿")
plt.ylabel("电影名称")
plt.xlabel("票房/亿")

plt.show()
原文地址:https://www.cnblogs.com/kogmaw/p/12558936.html