Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用python在条形图中使用matplotlib设置x标签_Python_Matplotlib - Fatal编程技术网

使用python在条形图中使用matplotlib设置x标签

使用python在条形图中使用matplotlib设置x标签,python,matplotlib,Python,Matplotlib,我需要将bjp inc和CPI标签作为x标签放在适当的位置 N = 1 ind = np.arange(N) width = 0.3 fig = plt.figure() ax = fig.add_subplot(111) bx = fig.add_subplot(111) cx = fig.add_subplot(111) yvals = [1] rects1 = ax.bar(0, yvals, width, color='g') zvals = [2] rects2 = ax.b

我需要将bjp inc和CPI标签作为x标签放在适当的位置

N = 1
ind = np.arange(N) 
width = 0.3  

fig = plt.figure()
ax = fig.add_subplot(111)
bx = fig.add_subplot(111)
cx = fig.add_subplot(111)

yvals = [1]
rects1 = ax.bar(0, yvals, width, color='g')
zvals = [2]
rects2 = ax.bar(0.5, zvals, width, color='r')
wvals = [1]
rects3 = ax.bar(1.0, wvals, width, color='b')

ax.set_ylabel('Percentage')
ax.set_xlabel('BJP   INC   CPI')

vals = [3]
rects4 = bx.bar(2.0, vals, width, color='g')
als = [2]
rects5 = bx.bar(2.5, als, width, color='r')
ls = [1]
rects6 = bx.bar(3.0, ls, width, color='b')
iyvals = [1.5]
rects7 = cx.bar(4.0, iyvals, width, color='g')
izvals = [2]
rects8 = cx.bar(4.5, izvals, width, color='r')
iwvals = [3]
rects9 = cx.bar(5.0, iwvals, width, color='b')

ax.legend( (rects1[0],rects2[0],rects3[0]), ('positive','negative','neutral') 
)

def autolabel(rects):
    for rect in rects:
        h = rect.get_height()

        ax.text(rect.get_x()+rect.get_width()/2, 1*h, '%d'%int(h),
                ha='center', va='bottom')

autolabel(rects1)
autolabel(rects2)
autolabel(rects3)
autolabel(rects4)
autolabel(rects5)
autolabel(rects6)
autolabel(rects7)
autolabel(rects8)
autolabel(rects9)

plt.show()

什么是正确的位置?假设我需要红色条下面的标签