2012-12-26 70 views
10

时消失,我有以下数据:Python的Pyplot条形图酒吧使用对数刻度

20120219,\\n,43166053 
20120220,\\n,46813269 
20120221,\\n,47277204 
20120222,\\n,46344556 
20120223,\\n,26926236 
20120224,\\n,6472506 
20120225,\\n,39580476 
20120226,\\n,55968342 
20120227,\\n,32889948 
20120228,\\n,32116361 
20120229,\\n,32424829 
20120301,\\n,56123889 
20120302,\\n,67102459 
20120303,\\n,81681885 
20120304,\\n,85740021 
20120305,\\n,83874668 
20120306,\\n,83606683 
20120307,\\n,56660981 
20120308,\\n,44534668 
20120309,\\n,37532071 
20120310,\\n,39260242 
20120311,\\n,40491186 
20120312,\\n,39041085 
20120313,\\n,27010562 
20120314,\\n,44121900 
20120315,\\n,87750645 
20120316,\\n,86588523 
20120317,\\n,86121469 
20120318,\\n,89343506 
20120319,\\n,89198664 
20120320,\\n,90273127 

我有以下代码来创建柱状图:

import matplotlib 
matplotlib.use('Agg') 
from matplotlib.mlab import csv2rec 
import matplotlib.pyplot as plt 
import matplotlib.dates as mdates 
from pylab import * 
from datetime import datetime 
import dateutil 
import sys 
import matplotlib.ticker as mticker 

y = []                          

input = open(sys.argv[1], 'r')                                   

data = csv2rec(input, names=['date', 'symbol', 'count'])      

for item in data['count']: 
     y.append(item) 

time_vec = [datetime.strptime(str(x),'%Y%m%d') for x in data['date']] 

rcParams['figure.figsize'] = 18, 7 
rcParams['font.size'] = 8 

N = len(y) 

ind = range(N) 

fig = plt.figure()        # Setup the figure 

ax = fig.add_subplot(111)      # Setup the subplot 
ax.bar(ind, y, align='center')     # Setup the Y Bars 

ax.set_ylabel('Counts') 

ax.set_title('Collected By Day')    

ax.set_xticks(ind) 
ax.set_xticklabels(time_vec) 
ax.grid()          

fig.autofmt_xdate(bottom=0.2, rotation=90, ha='left') 

plt.yscale('log') 

plt.savefig(str(sys.argv[1] + ".png")) 

这将创建以下图表:

day bar graph

如果我删除 “plt.yscale( '登录')” 行,然后我得到完整的酒吧。但是,因为我想添加其他线我真的需要这个有一个对数y尺度。基于一些搜索,我相信这是一个pyplot中的错误,但我似乎无法找到解决方案。有谁知道如何获得对数棒图来真正显示酒吧?

+0

这与其说是一个错误,但日志的属性的结果。为条形图绘制的矩形从'0'开始,并且'log(0)'未定义,因此矩形被拧紧。 – tacaswell

+2

http://stackoverflow.com/questions/17952279/logarithmic-y-axis-bins-in-python/17952890#17952890 < - 解决问题的替代方法。 – tacaswell

回答

相关问题