2014-10-30 227 views
0

我使用matplotlib繪製條形圖,一切正常。當X軸上的「文本標籤」對於每個數據點太長時,則文本重疊,如圖所示。我還嘗試將對齊方式旋轉到和度,但文字超出了框架。X軸文本重疊 - Matplotlib

enter image description here

X = [1,2,3,4,5,6] 
Y = [55,46,46,36,27,9] 
point_labels =[50,38,25,6,6,6] 
fig, axes = plt.subplots(1) 
ax2 = axes 
n=7 
ind=np.arange(n) 
width=0.1 
axis_font = {'fontname':'Arial', 'size':'11'} 
Color = ['0.1','0.2','0.3','0.4','0.5','0.6'] 

bar = ax2.bar(X,Y,align="center",width=0.5,color=Color) 
bar[0].set_color('r') 

plt.xticks(ind+width/2, ('','Insufficient skills','Complex hardware and software','High initial investments','Complexity in collection and storing data','Insufficient hardware power for computing','Data collaboration'),horizontalalignment='center') 

plt.ylabel('in precentage (%)') 

text(4.6,52, '100% = 11 responses', style='italic',bbox={'facecolor':'red', 'alpha':0.5, 'pad':10}) 

axes.yaxis.grid() 
axes.set_ylim([0,60]) 

plt.show() 

任何人都可以提出一個想法,以解決這一問題?

+0

您不能添加圖例來代替軸標籤嗎? – giosans 2014-10-30 13:01:33

+0

@giosans如果我找不到解決方案,這將是我的最後一個方法..但我相信這應該有一個解決方案! – 2014-10-30 13:06:09

回答

1

我能想到的最好的方法是將旋轉設置爲垂直改變圖形擴展並運行plt.tight_layout()。 這些將是你的代碼的最後3行:

mngr = plt.get_current_fig_manager() 
mngr.window.setGeometry(50,50,960, 640) 
plt.tight_layout() 

或者,你應該使用多線,\n。 請參閱http://matplotlib.org/examples/pylab_examples/multiline.html enter image description here