彭于晏的女友在python中⽤matplotlib绘制简单的横向和纵向条形图绘制横向条形图:
plt.barh(x,y,height=0.2,color="red",label="第⼀天")
#x,y为横纵坐标数据,height设置条形图的宽度,color设置条形图颜⾊,label设置条形图图列
绘制三条条形图的代码⽰例如下:
from matplotlib import pyplot as plt
from matplotlib import font_manager
#调⽤中⽂字体
my_font = font_manager.FontProperties(fname ="C:/WINDOWS/Fonts/STSONG.TTF")
#设置图形⼤⼩
plt.figure(figsize=(15,12),dpi = 80)
#数据
小s骂黄子佼
a =["唐⼈街探案","中国⼥排","战狼2","刺杀⼩说家","⼤闹天宫","肖申克的救赎"]
b_1 =[23,34,12,45,34,45]
b_2 =[34,12,35,13,26,32]
b_3 =[23,15,25,36,24,17]
殷叶子个人资料height = 0.2
a1 = list(range(len(a)))
a2 =[i+height for i in a1]#坐标轴偏移
a3 =[i+height*2 for i in a1]
#绘图
plt.barh(range(len(a)),b_1,height= height,label ="第⼀天",color ="#FFC125")
plt.barh(a2,b_2,height= height,label ="第⼆天",color ="#969696")
plt.barh(a3,b_3,height= height,label ="第三天",color ="#473C8B")
#绘制⽹格
#y轴坐标刻度标识
#添加图例
plt.legend(prop = my_font)
#添加横纵坐标,标题
plt.xlabel("票房/亿元",fontproperties = my_font,fontsize = 16)
plt.ylabel("电影名称",fontproperties = my_font,fontsize = 16)
plt.title("1,2,3号电影实时票房统计图",fontproperties = my_font,fontsize = 24)
#显⽰图形
plt.show()
结果如下:
横向条形图代码:
plt.barh(x,y,width= bar_width,color="red",label="第⼀天")
#x,y为横纵坐标数据,width设置条形图的宽度,color设置条形图颜⾊,label设置条形图图列⽰例代码:
from matplotlib import pyplot as plt
from matplotlib import font_manager
杭州市民卡服务中心
#调⽤中⽂字体
my_font = font_manager.FontProperties(fname ="C:/WINDOWS/Fonts/STSONG.TTF") #设置图形⼤⼩
plt.figure(figsize=(15,12),dpi = 80)
#数据
a =["唐⼈街探案","中国⼥排","战狼2","刺杀⼩说家","⼤闹天宫","肖申克的救赎"]
b_1 =[23,34,12,45,34,45]
b_2 =[34,12,35,13,26,32]
b_3 =[23,15,25,36,24,17]
bar_width = 0.2
糯米饭a1 = list(range(len(a)))
a2 =[i+bar_width for i in a1]
a3 =[i+bar_width*2 for i in a1]
#绘图
plt.bar(range(len(a)),b_1,width= bar_width,label ="第⼀天",color ="#FFC125")
plt.bar(a2,b_2,width= bar_width,label ="第⼆天",color ="#969696")
plt.bar(a3,b_3,width= bar_width,label ="第三天",color ="#473C8B")
#绘制⽹格
#y轴坐标刻度标识
#添加图例
plt.legend(prop = my_font)
#添加横纵坐标,标题
plt.ylabel("票房/亿元",fontproperties = my_font,fontsize = 18)
plt.xlabel("电影名称",fontproperties = my_font,fontsize = 18)
plt.title("1,2,3号电影实时票房统计图",fontproperties = my_font,fontsize = 24)香港游攻略
#显⽰图形
plt.show()
结果图: