蛋痛并继续蛋痛吧,吧频率图的程序补完- -,依赖pygooglechart @ pygooglechart.slowchop.com
然后不负责任的贴代码走人,output_fqcd是前一个程序的输出- - Python不支持unicode的模块名么?
# -*- coding: UTF-8 -*-
from output_fqcd import fanfou_data
mapdata = map(lambda data: data['time'][2:7] ,fanfou_data)
def reduce_func(d,r):
if r in d:
d[r] = d[r]+1
else:
d[r] = 1
return d
data = reduce(reduce_func,mapdata,{})
new_data = []
for x,y in data.iteritems():
new_data.append((x,y))
new_data.sort(lambda a,b: cmp(a[0],b[0]))
print(new_data)
x_data = []
y_data = []
for item in new_data:
x_data.append(item[0])
y_data.append(item[1])
from pygooglechart import Chart
from pygooglechart import StackedVerticalBarChart
from pygooglechart import Axis
min_y = 0 #min(data)
max_y = max(y_data)
chart = StackedVerticalBarChart(600, 375, y_range=[min_y, max_y])
chart.set_title('Search Count of "番茄操蛋"')
chart.add_data(y_data)
chart.set_bar_width(30)
left_axis = range(min_y, max_y + 1, max_y/10)
chart.set_axis_labels(Axis.LEFT, left_axis)
# X axis labels
chart.set_axis_labels(Axis.BOTTOM, x_data)
chart.download('fanfou.png')
c为学生编程的例子
回复删除c例子搜索回文