我是使用python生成条形图的新手。我设法编写了以下代码来生成条形图。由代码生成的图形随此附在帖子中。
method = ['Fx', 'Lx']
times = ['pre process', 'prop calc', 'moc calc', 'total']
pre_processing = [36, 36]
prop_calc = [45, (9.0/60.0)]
moc_calc = [73, (109-(36+9.0/60.0))]
total = [154, 109]
null = [0,0]
n_groups = 2
# create plot
fig, ax = plt.subplots()
index = np.arange(n_groups)
bar_width = 0.2
opacity = 0.8
rects1 = plt.bar(index, pre_processing, bar_width,
alpha=opacity,
color='c',
label='pre_processing')
rects2 = plt.bar(index + bar_width, prop_calc, bar_width,
alpha=opacity,
color='r',
label='prop_calc')
rects3 = plt.bar(index + 2*bar_width, moc_calc, bar_width,
alpha=opacity,
color='g',
label=times[2])
rects4 = plt.bar(index + 3*bar_width, total, bar_width,
alpha=opacity,
color='b',
label=times[3])
rects5 = plt.bar(index+4*bar_width,null,bar_width,
alpha=opacity,
color='w')
plt.ylabel('Time [min]')
plt.xticks(index + bar_width, method)
fontP = FontProperties()
fontP.set_size('medium')
plt.legend(loc='upper center', bbox_to_anchor=(0.5, 1.00),
fancybox=True, ncol=3, prop=fontP)
fig.savefig("Time comparison", format='eps', dpi=1200)
plt.tight_layout()
plt.show()
有人可以告诉我如何在每个小节的顶部打印每个y变量的单个值吗?