我已經生成柱狀圖看起來像這樣的靠不住之間的間距:matplotlib BARH產生酒吧
注意標籤上的垂直間距不均勻出於某種原因;我不確定這是否與我已經分配了滴答或任何實際放置文本的機制有關。相關代碼:
height_factor = 40.0
ind = np.linspace(0,len(sorted_totals)*height_factor,num=len(sorted_totals))
width = 0.25
fig = plt.figure(figsize=(15.5, 8.75),dpi=300)
p1 = plt.barh(ind,map(int,sorted_composite[:,0]),color='blue',align='center',height=height_factor)
p1 = plt.barh(ind,map(int,sorted_composite[:,2]),color=(0.75,0.1,0.1),align='center',height=height_factor)
plt.ylabel('# of Picks (blue) + # of Bans (red)')
plt.yticks(ind, sorted_totals[:,0])
plt.subplots_adjust(bottom=0.05, left=0.14,right=0.95,top=0.95)
plt.ylim([ind.min() - height_factor, ind.max() + height_factor])
我的數據存儲在sorted_composite和IND是我用來放置棒(的ytick位置)的值。我正在使用linspace生成均勻間隔的小節,這是唯一的作品,我不確定原因。
我在想,您的問題可能與具有所有這些酒吧而臨時抱佛腳,但我一直在試圖從你的代碼5到〜50條,這裏沒有問題。 – 2012-01-03 04:22:01
是的,我有一種感覺這是一個像素放置四捨五入問題..即如果你有一個8像素高的圖像,並且想要通過中心繪製一條線,你是否沿着像素行4或像素行5繪製;無論哪種方式很糟糕 – user1127062 2012-01-03 07:34:43
在一個側面說明我報復一個平凡的測試用例不好的結果: '從numpy的進口*' 從pylab進口* 數據=零(50)+10 IND =人氣指數(10) barh(ind,data) show()' 看起來很糟糕 – user1127062 2012-01-03 07:38:15