2013-12-18 150 views
0
headings=[['Jan to Feb'], ['Feb to Mar'], ['Mar to Apr'], ['Apr to May'], ['May to June'], ['Jun to July'], ['July to Aug'], ['Aug to Sep'], ['Sep to Oct'], ['Oct to Nov']] 
incoming=[[27, 42, 66, 85, 65, 64, 68, 68, 77, 58], 
     [24, 39, 58, 79, 60, 62, 67, 62, 55, 35], 
     [3, 3, 8, 6, 5, 2, 1, 6, 22, 23], 
     [3, 3, 8, 6, 5, 2, 1, 6, 22, 23], 
     [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 
     ] 
joint=[[486, 511, 615, 825, 760, 693, 848, 639, 651, 657] 
    [444, 482, 562, 793, 729, 666, 812, 599, 592, 597] 
    [42, 29, 53, 32, 31, 27, 36, 40, 59, 60] 
    [29, 28, 35, 32, 31, 27, 36, 40, 59, 60] 
    [13, 1, 18, 0, 0, 0, 0, 0, 0, 0] 
    ] 

見照片: http://s1362.photobucket.com/user/superempl/media/figure_1_zps782354d7.png.htmlx軸標籤定位(2D)

我需要於x軸的標籤轉移到右。我試過了:

plot.set_xticklabels(headings,multialignment='right') 

但這沒有效果。

有人可以解釋一下必須做些什麼來改變這些標籤的位置到每個條的中心。

我的代碼如下:

import pylab as p 
from matplotlib.ticker import MaxNLocator 

fig = p.figure(figsize=(20,8)) 
plot = fig.add_subplot(111)    

ind = range(len(headings))   

bar1 = plot.bar(ind,joint[0],facecolor='#777777') 
bar2 = plot.bar(ind,outgoing[0],facecolor='#B0E0E6') 

# x-axis 
plot.xaxis.set_major_locator(MaxNLocator(10)) 
plot.set_xticklabels(headings) 

p.show() 

回答

2

也許,請嘗試以下操作:在蜱

# headings should be simple list 
headings=['Jan to Feb', 'Feb to Mar', 'Mar to Apr', 'Apr to May', 'May to June', 
      'Jun to July', 'July to Aug', 'Aug to Sep', 'Sep to Oct', 'Oct to Nov'] 

中心酒吧與align='center'

bar1 = plot.bar(ind,joint[0],facecolor='#777777', align='center') 

然後設置刻度位置刻度標籤:

ax.xaxis.set_ticks(ind) 
ax.xaxis.set_ticklabels(h) 

ax.set_xlim(ind[0]-.5,ind[-1]+.5) # set width of axis 
fig.canvas.draw() # don't forget to draw changes 

這樣標籤將在下面的杆爲中心: Example Bars

參見進一步使用實施例中的matplotlib庫(例如,23)。