条形图绘制
- 竖着的条形图:
bar(x, y
- 横着的条形图:
barh (x, y)
题目
x = ["战狼", "你好李焕英", "哪吒之魔童降世", "流浪地球", "唐人街探案"]
y = [56.94, 54.13, 50.36, 46.86, 45.22]
- 具体的介绍全在代码里面,直接看代码就行,这个和折线图,散点图有异曲同工之妙
竖着的图形
from matplotlib import pyplot as plt
from matplotlib import font_manager
my_font = font_manager.FontProperties(fname = r'C:\WINDOWS\FONTS\MSYHL.TTC')
x = ["战狼", "你好李焕英", "哪吒之魔童降世", "流浪地球", "唐人街探案"]
y = [56.94, 54.13, 50.36, 46.86, 45.22]
plt.figure(figsize=(20,8), dpi = 80)
plt.bar(range(len(x)), y, width = 0.5)
plt.xticks(range(len(x)), x, fontproperties=my_font)
plt.savefig("./电影票房.png")
plt.title("2021年前五的电影", fontproperties = my_font)
plt.xlabel("电影名", fontproperties = my_font)
plt.ylabel("票房(亿)", fontproperties = my_font)
plt.show()
横着的图像
from matplotlib import pyplot as plt
from matplotlib import font_manager
my_font = font_manager.FontProperties(fname = r'C:\WINDOWS\FONTS\MSYHL.TTC')
x = ["战狼", "你好李焕英", "哪吒之魔童降世", "流浪地球", "唐人街探案"]
y = [56.94, 54.13, 50.36, 46.86, 45.22]
plt.figure(figsize=(20,8), dpi = 80)
plt.barh(range(len(x)), y, height=0.5)
plt.yticks(range(len(x)), x, fontproperties=my_font)
plt.savefig("./电影票房(横).png")
plt.title("2021年前五的电影", fontproperties = my_font)
plt.ylabel("电影名", fontproperties = my_font)
plt.xlabel("票房(亿)", fontproperties = my_font)
plt.show()