我已经使用谷歌搜索,但我没有找到答案。使用百分比单位绘制数据
我的问题:
我有数据阵列,我想用百分比单位阴谋。例如:
数据:[1,3,1,3,3,2,4,5]
1:0.25
2:0.125
3: 0.375
4:0.125
5:0.125
PS:我不想使用[R只蟒蛇,matplotlib如果需要numpy的
我已经使用谷歌搜索,但我没有找到答案。使用百分比单位绘制数据
我的问题:
我有数据阵列,我想用百分比单位阴谋。例如:
数据:[1,3,1,3,3,2,4,5]
1:0.25
2:0.125
3: 0.375
4:0.125
5:0.125
PS:我不想使用[R只蟒蛇,matplotlib如果需要numpy的
编辑:对不起,看错你的问题,我想你的意思只蟒蛇。有人会希望张贴matplotlib或numpy解决方案。
这里有一个方法通过列表进行排序,做到这一点:
>>> a = [1, 3, 1, 3, 3, 2, 4, 5]
>>>
>>> def unit_percents(L1):
... ret = {}
... L = L1[:]
... sorted(L)
... if L:
... cur_count = 1
... for i in range(len(L)-1):
... cur_count+=1
... if L[i] != L[i+1]:
... ret[L[i]]=float(cur_count)/len(L)
... cur_count=1
... ret[L[-1]]=float(cur_count)/len(L)
... return ret
...
>>> unit_percents(a)
{1: 0.25, 2: 0.25, 3: 0.375, 4: 0.25, 5: 0.125}
也:
>>> dict([(x,float(a.count(x))/len(a)) for x in set(a)])
{1: 0.25, 2: 0.125, 3: 0.375, 4: 0.125, 5: 0.125}
>>>
感谢您的回答,如果他们还没有这样做的功能,我会用你的方式。非常感谢 – bioinfornatics 2011-04-27 06:27:30
看看在matplotlib的HIST功能:http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.hist numpy的也有直方图功能: http://docs.scipy.org/doc/numpy/reference/generated/numpy.histogram.html
您的问题是关于如何在ylabel中放入“%”,或者您想要转换数据吗?如果是,如何? – 2011-04-26 20:41:04
我使用matplotlib.ticker作为格式标签。我搜索一个模块/功能...了解部分人口的表示形式:http://en.wikipedia.org/wiki/Population。 @Ding似乎有一个“手动”,但好方法。 – bioinfornatics 2011-04-27 06:25:52