码迷,mamicode.com
首页 > 其他好文 > 详细

绘制条形图

时间:2019-04-07 20:33:34      阅读:191      评论:0      收藏:0      [点我收藏+]

标签:pid   res   orm   otl   fas   设置图   spi   pytho   img   

# coding = utf - 8
from matplotlib import pyplot as plt

a = ["Scarlet ball rise", "spider-man", "Dunkirk", "War Wolf 2"]
b_16 = [15746, 312,4497,319]
b_15 = [12357,156,2045,168]
b_14 = [2358,399,2358,362]

bar_width = 0.2

x_14 = list(range(len(a)))
x_15 = [i + bar_width for i in x_14]
x_16 = [i + bar_width * 2 for i in x_14]

# 设置图形大小
plt.figure(figsize=(15, 8), dpi=80)

plt.bar(range(len(a)), b_14, width=bar_width, label = "September 14th")
plt.bar(x_15, b_15, width=bar_width, label = "September 15th")
plt.bar(x_16, b_16, width=bar_width, label = "September 16th")

# 设置x轴的刻度
plt.xticks(x_15, a)

# 设置图例
plt.legend()

plt.show()

  技术图片

 

# coding = utf - 8
from matplotlib import pyplot as plt

# a = ["战狼2", "速度与激情8", "功夫瑜伽", "西游伏妖篇", "变形金刚5", "摔跤吧爸爸"]
a = ["War Wolf 2", "Fast and furious 8", "Kung fu yoga", "Journey to the west", "Transformers 5", "Wrestling, daddy"]
b = [56.01,26.94,17.53,16.49,15.45,12.96]

# 设置图片大小
plt.figure(figsize=(15, 8), dpi=80)
# 绘制横向条形图
plt.barh(range(len(a)), b, height =0.3, color = "orange")
# 设置字符串到x轴
plt.yticks(range(len(a)), a)

# 绘制网格
plt.grid(alpha = 0.3)
plt.savefig("./movie.png")

plt.show()

  技术图片

 

# coding = utf - 8
from matplotlib import pyplot as plt

# a = ["战狼2", "速度与激情8", "功夫瑜伽", "西游伏妖篇", "变形金刚5", "摔跤吧爸爸"]
a = ["War Wolf 2", "Fast and furious 8", "Kung fu yoga", "Journey to the west", "Transformers 5", "Wrestling, daddy"]
b = [56.01,26.94,17.53,16.49,15.45,12.96]

# 设置图片大小
plt.figure(figsize=(15, 8), dpi=80)
# 绘制条形图
plt.bar(range(len(a)), b, width=0.3)
# 设置字符串到x轴
plt.xticks(range(len(a)), a)

plt.savefig("./movie.png")

plt.show()

  技术图片

绘制条形图

标签:pid   res   orm   otl   fas   设置图   spi   pytho   img   

原文地址:https://www.cnblogs.com/mjn1/p/10666797.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!