尝试使用matplotlib

时间:2018-06-12 15:02:29

标签: python-3.x numpy matplotlib

有人可以帮我添加Y值到我的酒吧。我试过但没有运气。 你会建议什么使这段代码看起来更干净?我觉得它可以改进,但我还处于学习阶段。

import matplotlib.pyplot as plt
import numpy as np

#style
plt.style.use("seaborn-colorblind")

# bar width
bar_width = 0.25

# data
months = ['April', 'May', 'June']
application = [18, 44, 7]
infrastructure = [27, 36, 20]

# convert months to array
months_array = np.arange(len(months))

# y labels
plt.ylabel('# of Errors\n', fontsize=14, fontweight='bold')

# add minor ticks on y axis
yticks = np.arange(0,45,5)
plt.yticks(yticks)

# graph title
plt.title("Fatal Errors from April 23rd - June 11th", fontsize=18,            fontweight='bold')

# bars names
plt.xticks(months_array + bar_width-0.125, months, fontweight='bold')


# bars
plt.bar(months_array, application, width=bar_width, color='#5cbae6',     edgecolor='white', label='Application')
plt.bar(months_array + bar_width, infrastructure, width=bar_width,     color='#b6d957', edgecolor='white', label='Infrastructure')

# legend
plt.legend()

# show graph
plt.show()

这就是我目前所拥有的: Click here for picture

但是我想要这样的东西没有百分比和值在栏内: Click here for picture - not my picture

0 个答案:

没有答案