import matplotlib.pyplot as plt
import random
from pylab import mpl
设置显示中文字体
mpl.rcParams["font.sans-serif"] = ["SimHei"]
设置正常显示符号
mpl.rcParams["axes.unicode_minus"] = False
0.准备X,Y坐标的数据
x:电影名字
movie_name = ["雷神3","正义联盟","东方快车","寻梦环游记","全球风暴","降魔传","追捕","七十七天","密战","狂兽","其它"]
x = range(len(movie_name))
y:票房数据
y = [73835,57767,22354,15969,14839,8716,8318,7916,6764,52222,13453]
1.创建画布
plt.figure(figsize=(20,8),dpi=100) #figsize,设置图像大小比例为20:8,dpi,图像的清晰度
2.绘制图像
plt.bar(movie_name,y,width=0.5,color=["b","r","g","y","c","m","y","k","c","g","b"])
2.1 修改x轴的刻度显示
plt.xticks(movie_name,movie_name) #其实我感觉是多此一举,或许后面有更多的考量
2.2 添加网格线显示
plt.grid(linestyle="--",alpha = 0.5 )
2.3 添加标题
plt.title("电影票房收入比")
plt.show()
标签:plt,name,movie,mpl,matplotlib3,import,图形,绘制 From: https://www.cnblogs.com/yangzilaing/p/17123661.html