2016-12-14 54 views
0

頻率A像樣方式我創建從每個類的frequeny以下直方圖在訓練集繪製的43個不同類別

enter image description here

每個類的標籤太長且類似於

Speed limit (20km/h) 

我可以將每個標籤放在酒吧本身嗎?

+0

您可以考慮這個分成兩個問題作爲一個好像是我怎麼能標註直方圖(改變繪圖大小等),而第二個是如何添加圖例。你也可以考慮擴大對第二部分的解釋,因爲我猜測你甚至在那裏問什麼。因爲它似乎是一個基於概率密度的三組相關度量到一個精度水平 - 我可以完全關閉 - 這將需要更多的圖例,然後是軸標籤。 – JGreenwell

+0

問題更新 –

+0

@JGreenwell還創建了第二個問題http://stackoverflow.com/questions/41133542/plotting-training-data-with-43-distinct-classes –

回答

3

也許這樣?

enter image description here

import numpy as np 
import matplotlib.pyplot as plt 

N=5 
xlabel = ["Speed limit ("+str(i)+"km/h)" for i in range(0,N)] 
xs = np.arange(0,7,1.5) 
ys = [8,6,10,7,9] 
width = 0.3*np.ones(N) 

fig, ax = plt.subplots() 
bars = ax.bar(xs, ys, width, color='k',alpha=0.3) 
plt.xticks(xs, xlabel,rotation=270) 

for i,bar in enumerate(bars): 
    height = bar.get_height() 
    ax.text(bar.get_x() + bar.get_width()/2., 0.1*height, 
       '%s' % xlabel[i],rotation=90,ha='center', va='bottom') 

plt.show() 

把它改成單槓情節:

enter image description here

import numpy as np 
import matplotlib.pyplot as plt 

N = 5 
xlabel = ["Speed limit ("+str(i)+"km/h)" for i in range(0,5)] 
xs = np.arange(0,5)/2 
ys = [8,6,10,7,9] 
width = 0.3*np.ones(N) 

fig, ax = plt.subplots() 
bars = ax.barh(xs, ys, width, color='k',alpha=0.3) 
plt.xticks([]) 

for i,bar in enumerate(bars): 
    height = bar.get_height() 
    ax.text(bar.get_x()+3, bar.get_y()+bar.get_height()/3, 
       '%s' % xlabel[i],rotation=0,ha='center', va='bottom') 
plt.tight_layout() 
plt.show() 
+1

什麼是* width *在bars = ax.bar(xs ,ys,width,color ='k',alpha = 0.3)? nvm使用0.5,它看起來不錯! –

+0

@SamHammamy:請參閱最新的答案! – Mahdi

+1

優秀的答案。我正在努力使其成爲* barh *。如果你可以補充一點,我會很棒! –