[英]How to plot a bar chart with bar values?
我正在尝试用python绘制酒吧字符。 以下是我的代码。 我每个酒吧的价值都为0
。
from __future__ import division
import matplotlib.pyplot as plt
import numpy as np
x = [0,1,2,3,4,5,6,7,8,9,10,11,12]
freq = [0.93, 0.87,0.86,0.87,0.93,0.84,0.74,0.79,0.78,0.95,0.88,0.8, 0.71]
width = 0.5 # width of the bars
fig, ax = plt.subplots()
rects1 = ax.bar(x, freq, width, color='r')
ax.set_ylim(0,1)
ax.set_ylabel('auc-roc')
ax.set_xticks(np.add(x,(width/2.2))) # set the position of the x ticks
ax.set_xticklabels(('X1', 'X2', 'X3', 'X4', 'X5', 'X6', 'X7', 'X8', 'X9', 'X10', 'X11', 'X12', 'X13'))
def autolabel(rects):
for rect in rects:
height = rect.get_height()
ax.text(rect.get_x() + rect.get_width()/2., 1.0*height,
'%d' % (height),
ha='center', va='bottom')
autolabel(rects1)
plt.show()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.