2016-12-14 48 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 *。如果你可以补充一点,我会很棒! –