コード例 #1
0
def draw(df, x, y, title=None, **kwargs):
    my_options = copy.deepcopy(options)

    title = title if title else str(y)
    my_options['title']['text'] = title
    tmp = df[[x] + y]

    x_type = kwargs.pop('x_type') if 'x_type' in kwargs else 'datetime'
    x_labels = kwargs.pop('x_labels') if 'x_labels' in kwargs else None
    subtitle = kwargs.pop('subtitle') if 'subtitle' in kwargs else ''
     
    if x_type == 'datetime':
        tmp.set_index(x, inplace=True)
        tmp.index = tmp.index.to_datetime()
    else:
        my_options['xAxis']['type'] = x_type
        my_options['xAxis']['categories'] = df[x].tolist()

    if x_labels:
        my_options['xAxis']['categories'] = x_labels

    if 'options' in kwargs:
        my_options.update(kwargs.get('options'))
        kwargs.pop('options')

    if 'width' in kwargs:
        my_options['width'] = kwargs.get('width')

    if 'height' in kwargs:
        my_options['height'] = kwargs.get('height')

    if subtitle:
        my_options['subtitle']['text'] = subtitle

    if 'just_draw' not in kwargs:
        return charts.plot(tmp, options=my_options, show='inline', display=y, **kwargs)
    else:
        kwargs.pop('just_draw')
        figure = charts.plot(tmp, options=my_options, show='inline', display=y, **kwargs)
        print_html(figure.data)
コード例 #2
0
ファイル: test.py プロジェクト: Honglei1990/CodeFragment
series = [{
    'name': 'os X',
    'data': [8],
    'type': 'column'
}, {
    'name': 'windows',
    'data': [11],
    'type': 'column'
}, {
    'name': 'Ubuntu',
    'data': [5],
    'type': 'column'
}]
charts.plot(series,
            show='inline',
            options=dict(title=dict(text='This is test!')))

# In[42]:

rank_list = []
for i in item_infoX.find():
    rank_list.append(i['rank'])
rank_index = list(set(rank_list))
print(rank_index)

# In[45]:

rank_index.sort()
print(rank_index)
コード例 #3
0
    calc = 0
    for key in key_list:
        gen_data(key[0], key[1], re_list)
    gen_data(5000, 10000, re_list)
    for i in item_info.find():
        if '万' in i['price']:
            calc += 1
    re_list.append(['万元以上', calc])
    calc = 0
    for i in item_info.find():
        if '面议' in i['price']:
            calc += 1
    re_list.append(['面议', calc])


final_data(key_list, re_list)
for i in re_list:
    print(i)

'''options = {
    'charts': {'zoomType': 'xy'},
    'title': {'text': '58北京地区物品价格对比'},
    'subtitle': {'text': '来自风平浪静的明天'}
}
series = [{
    'type': 'pie',
    'name': 'Browser share',
    'data': [data for data in re_list],
}]
charts.plot(series, show='inline', options=options)'''
コード例 #4
0
ファイル: charts_0.1 .py プロジェクト: qchs/58
catelog = list(set(cate_list))
print(catelog)
print(len(catelog))

# In[73]:

post_times = [cate_list.count(i) for i in catelog]
print(post_times)

# In[74]:


def date_gen(type):
    length = 0
    if length <= len(catelog):
        for cates, times in zip(catelog, post_times):
            data = {'name': cates, 'data': [times], 'type': type}
            yield data
            #             print(data)
            length += 1


series = [i for i in date_gen('column')]
print(series)

# In[75]:

charts.plot(series, show='inline', options=dict(title=dict(text='aaa')))

# In[ ]:
コード例 #5
0
start = pd.Timestamp(time() - number_of_days * 86400, unit='s')

# In[ ]:

sensors = hp.get_sensors()
#sensors.remove('b325dbc1a0d62c99a50609e919b9ea06')

# In[ ]:

for sensor in sensors:
    s = sensor.get_data(head=start)
    # do an ugly operation to get localtime.  A simple tz_convert does not work: charts will always plot
    # in UTC.
    new_index_list = []
    for index_utc in s.index:
        new_index_list.append(index_utc +
                              index_utc.tz_convert(BXL).utcoffset())
    s.index = pd.DatetimeIndex(new_index_list)
    try:
        # plot with charts (don't show it) and save html
        charts.plot(pd.DataFrame(s),
                    stock=True,
                    save=os.path.join(c.get('data', 'folder'), 'figures',
                                      'TimeSeries_' + sensor.key + '.html'),
                    show=False)
    except Exception as e:
        print(e)

# In[ ]:
コード例 #6
0
ファイル: linear_chart.py プロジェクト: adorn331/CrawlerToy
    'subtitle': {
        'text': '可视化统计图表'
    },
    'xAxis': {
        'categories': [i for i in get_dates('2015-12-25', '2016-1-2')]
    },
    'yAxis': {
        'title': {
            'text': '数量'
        }
    }
}

series = [i for i in get_data_within('2015-12-25', '2016-1-2', require)]

charts.plot(series, options=options, show='inline')
# options=dict(title=dict(text='Charts are AWESOME!!!'))

#手动输入示范效果
# series = [
#     {
#     'name': 'OS X',
#     'data': [11,2,3,4],
#     'type': 'line',
#     'y':5
# }, {
#     'name': 'Ubuntu',
#     'data': [8,5,6,7],
#     'type': 'line',
#     'color':'#ff0066'
# }, {
コード例 #7
0
# In[ ]:

cache_min = caching.Cache(variable='elec_daily_min')
cache_max = caching.Cache(variable='elec_daily_max')
dfdaymin = cache_min.get(sensors=sensors)
dfdaymax = cache_max.get(sensors=sensors)

# The next plot shows that some periods are missing.  Due to the cumulative nature of the electricity counter, we still have the total consumption.  However, it is spread out of the entire period.  So we don't know the standby power during these days, and we have to remove those days.

# In[ ]:

if DEV:
    sensor = hp.search_sensors(key='3aa4')[0]
    df = sensor.get_data(head=pd.Timestamp('20151117'),
                         tail=pd.Timestamp('20160104'))
    charts.plot(df, stock=True, show='inline')

# In[ ]:

# Clean out the data:
# First remove days with too low values to be realistic
dfdaymin[dfdaymin < 10] = np.nan
# Now remove days where the minimum=maximum (within 1 Watt difference)
dfdaymin[(dfdaymax - dfdaymin) < 1] = np.nan

# In[ ]:

if DEV:
    charts.plot(dfdaymin, stock=True, show='inline')

# In[ ]:
コード例 #8
0
ファイル: datanalysis.py プロジェクト: tomdev2008/analyze
    if len(i['area']) == 1:
        item_info.update_one({'_id':i['_id']},{'$set':{'area':'不明'}})
        #print('不明')
    elif len(i['area']) == 2 and '-' not in i['area'][1]:
        item_info.update_one({'_id':i['_id']},{'$set':{'area':'不明'}})
        #print('不明')
    elif len(i['area']) == 3:
        item_info.update_one({'_id':i['_id']},{'$set':{'area':'北京' + '-' + i['area'][0]}})
        #print('北京' + '-' + i['area'][0])
    else:
        item_info.update_one({'_id':i['_id']},{'$set':{'area':i['area'][1]}})
        #print(i['area'][1])

area_list = []
for i in item_info.find():
    if i['area'] != '不明':
        if '北京' in i['area']:
            area_list.append(i['area'].split('-')[1])
        else:
            area_list.append('其他省份')
area_index = list(set(area_list))
print(area_index)

post_times = []
for index in area_index:
    post_times.append(area_list.count(index))
print(post_times)

series = [data for data in data_gen('column')]
charts.plot(series, show='inline', options=dict(title=dict(text='58同城北京城区物品发帖量')))
コード例 #9
0
        "xAxis": {
            "type": 'category',
            "crosshair": True
        },
        "yAxis": {
            "min": 0,
            # "title": {
                "text": '金额 (百万)'
            }
        }
    }
    totalHgMoney = []
    for key, value in sumPdData[CONST_SUM_COLUMN].to_dict().items():
        totalHgMoney.append([key, value])
    series[0]['data'] = totalHgMoney
    IPython.core.display.publish_display_data({'text/html': charts.plot(series, options=options, show='inline').data})


def ag_hgtj_month(p_base_data):
    '''
    A股的高管增持统计(根据月份)
    :return:
    '''
    CONST_TABLE_NAME = 'agzc'
    CONST_SUM_COLUMN = '变动金额'
    CONST_BASE_DATE = p_base_data

    series = [{
        'type': 'column',
        'name': '增持金额',
        'data': [],
コード例 #10
0
                 ['00后', age_dur(age)[4]]]
    }]
    options4 = {
        'title': {
            'text': '年龄分布'
        },
        'plotOptions': {
            'pie': {
                'dataLabels': {
                    'enabled': True,
                    'format': '{point.name}:<b> {point.percentage:.1f} %</b>'
                }
            }
        }
    }
    charts.plot(series4, options=options4)

    #标题中关键词曝光
    word = [u'嫘祖', u'祭祖', u'盐亭', u'绵阳']
    for i in range(len(word)):
        a = keyword(word, title_new)[i] + keyword(
            word, title_wechat)[i] + keyword(word, title_weibo)[i] + keyword(
                word, title_ba)[i]
        print "关键词:%s" % word[i], "出现总次数为:%s" % a, "新闻出现次数为:%s" % keyword(
            word, title_new)[i], "微信出现次数为:%s" % keyword(
                word, title_wechat)[i], "微博出现次数为:%s" % keyword(
                    word, title_weibo)[i], "贴吧出现次数为:%s" % keyword(
                        word, title_ba)[i]
    key_new = 0  # 新闻中关键词曝光总次数
    key_weibo = 0  # 微博中关键词曝光总次数
    key_wechat = 0
コード例 #11
0
ファイル: pipelines.py プロジェクト: pol9111/zhizhupaojiao
author_others_set = list(set(author_set))  # 去掉所有4部及以下作者
author_others_set.remove('others')  # 先删除others 已对应顺序
# appear_times.append(others_num)# 在列表里添加others的总作品数
# author_others_set.append('others')# 在列表里添加others

# print(others_num)
print(author_others_set)
print(appear_times)


# 把数据变成charts.plot所使用的格式
def data_gen(types):
    length = 0
    if length <= len(author_others_set):
        for author, times in zip(author_others_set, appear_times):
            data = {'name': author, 'data': [times], 'type': types}
            yield data
            length += 1


for i in data_gen('column'):
    print(i)

# 传入type参数, 所在柱状图
series = [data for data in data_gen('column')]
# 展示图片
charts.plot(series,
            show='inline',
            options=dict(title=dict(text='全本网小说主要作者与作品总数')))
コード例 #12
0
import charts
import sys
import numpy as np
import numpy.random
print(sys.path)


data = np.random.rand(10)
data2 = np.random.rand(10)*2
charts.plot(data, name='My list')
charts.plot(data2, name='My list2')
コード例 #13
0
	start_day += days
for date in index_time:
	a = list(time_list.find({'date':date}))
	count_time.append(len(a))
#
#线形图	
#options = {
#	'title':{'text':'百度发帖量统计'},
#	'xAxis':{'categories':index_time},
#	'yAxis':{'text':'数量'}
#}	
#series = [{'date':count_time,'name':'python贴吧分析','type':'line'}]
#charts.plot(series,show='inline',options=options)


#柱状图
tem_list = []
for i,j in zip(count_time,index_time):
	date={
		'name':j,
		'date':[i],
		'type':'column'		
	}
	tem_list.append(date)
options = {
	'title':{'text':'百度发帖量统计'},
	'subtitle':{'text':'可视化统计表'}
	'plotOptions':{'column':{'dataLabels':{'enabled':True}}}
}	
charts.plot(tem_list,show='inline',options=options)
コード例 #14
0
    def getMulti(self):
        s1List = []
        for file in self.file_list:
            s1List.append(self.getOne(file))

        return s1List

def etl(file_list):
    for file in file_list:
        file_txt='/Users/TiM/sysbench_file/'+file+'.txt'
        file_out='/Users/TiM/sysbench_file/'+file+'.out'
        if not os.path.exists(file_out):
            cmd='''grep "^\[" %s \
            |awk -F'(' '{print $1}'|sed -e "s/\[\ /\{'time':'/g" -e \
            "s/\ \]//g" -e "s/:\ /':'/g" -e "s/\ /','/g" -e "s/,'$/\}/g" \
            > %s''' % (file_txt,file_out)
            subprocess.call(cmd,shell=True)

etl(['oltp_point_select','oltp_read_only','oltp_read_write'])

file_list = [
            '/Users/TiM/sysbench_file/oltp_read_write.out',
            '/Users/TiM/sysbench_file/oltp_point_select.out',
            '/Users/TiM/sysbench_file/oltp_read_only.out'
            ]
char_1=MyCharts(file_list,'qps','16G 4core Benchmark')
res=char_1.getMulti()

charts.plot(res,options=char_1.options,show='inline',)

コード例 #15
0
cache_min = caching.Cache(variable='elec_min_night_0-5')
cache_max = caching.Cache(variable='elec_max_night_0-5')
dfdaymin = cache_min.get(sensors=sensors)
dfdaymax = cache_max.get(sensors=sensors)
dfdaymin.info()


# The next plot shows that some periods are missing.  Due to the cumulative nature of the electricity counter, we still have the total consumption.  However, it is spread out of the entire period.  So we don't know the standby power during these days, and we have to remove those days.  

# In[ ]:

if DEV:
    sensor = hp.search_sensors(key='3aa4')[0]
    df = sensor.get_data(head=pd.Timestamp('20151117'), tail=pd.Timestamp('20160104'))
    charts.plot(df, stock=True, show='inline')


# In[ ]:

def is_submeter(sensor, dfdaymin, dfdaymax):
    """
    Return True if this sensor is a sub-meter
    
    sensor = sensor object
    """
    
    
    other_sensors = sensor.device.get_sensors(sensortype='electricity')
    other_sensors.remove(sensor)
    if len(other_sensors) == 0:
コード例 #16
0
smooth = [-0.0136616324610853, -0.0402225653031136, -0.0891885271425559, -0.155185908028985, -0.219899195858309, -0.265313879077956, -0.286802183981697, -0.291757306592123, -0.289922067597462, -0.286772502661079, -0.28585204136226, -0.286624462076436, -0.288448773435939, -0.29111042880889, -0.29462422077717, -0.298774803391792, -0.303225314838625, -0.307863689709994, -0.31264798321422, -0.317405075707049, -0.321669366465032, -0.325012665815088, -0.327057916102116, -0.32785769286744, -0.327743919202184, -0.327060832384228, -0.326000330159904, -0.324624935604359, -0.322933130316997, -0.320856638217991, -0.318529669840097, -0.316326475798584, -0.314601752188257, -0.313214397843633, -0.311776748719551, -0.310231727957227, -0.308834031011567, -0.307787991770913, -0.306922816444578, -0.305952475143005, -0.304709589395159, -0.30348247422531, -0.302925074174484, -0.30374220226776, -0.306069409116789, -0.309456247890566, -0.313244894273009, -0.316797209080948, -0.319841304049062, -0.322225095634729, -0.323930648285666, -0.324759483959778, -0.324714645771904, -0.323970812748158, -0.322802387384562, -0.321310412036861, -0.319440599487196, -0.317073130316997, -0.314206381825192, -0.311029318127558, -0.307646371718058, -0.304356828351652, -0.301570215837967, -0.29998171640615, -0.300072724261983, -0.30192638417288, -0.305470550606986, -0.310404246341246, -0.315968373406836, -0.320944907750239, -0.324079214224742, -0.324556574173249, -0.322112442597518, -0.316986966919491, -0.309799503139502, -0.301318199245306, -0.292268426851028, -0.283659285009973, -0.27671259375517, -0.272667704689424, -0.272190038239891, -0.275291284805382, -0.281719009551322, -0.290589519682213, -0.300310199166483, -0.30876120244271, -0.31438823820421, -0.316638190658425, -0.316118908804157, -0.314022886553781, -0.311718582466062, -0.310219128415795, -0.310128026393089, -0.311828599109319, -0.315278380721729, -0.319904784507483, -0.324846973506367, -0.329273468142693, -0.332371633417039, -0.330434140196889, -0.318700330890727, -0.288821023533946, -0.235028315333709, -0.163427937991548, -0.0928554729403512, -0.0415163222135, -0.0139839190824463, -0.00313451126095741]
smooth = [-0.219899195858309, -0.265313879077956, -0.286802183981697, -0.291757306592123, -0.289922067597462, -0.286772502661079, -0.28585204136226, -0.286624462076436, -0.288448773435939, -0.29111042880889, -0.29462422077717, -0.298774803391792, -0.303225314838625, -0.307863689709994, -0.31264798321422, -0.317405075707049, -0.321669366465032, -0.325012665815088, -0.327057916102116, -0.32785769286744, -0.327743919202184, -0.327060832384228, -0.326000330159904, -0.324624935604359, -0.322933130316997, -0.320856638217991, -0.318529669840097, -0.316326475798584, -0.314601752188257, -0.313214397843633, -0.311776748719551, -0.310231727957227, -0.308834031011567, -0.307787991770913, -0.306922816444578, -0.305952475143005, -0.304709589395159, -0.30348247422531, -0.302925074174484, -0.30374220226776, -0.306069409116789, -0.309456247890566, -0.313244894273009, -0.316797209080948, -0.319841304049062, -0.322225095634729, -0.323930648285666, -0.324759483959778, -0.324714645771904, -0.323970812748158, -0.322802387384562, -0.321310412036861, -0.319440599487196, -0.317073130316997, -0.314206381825192, -0.311029318127558, -0.307646371718058, -0.304356828351652, -0.301570215837967, -0.29998171640615, -0.300072724261983, -0.30192638417288, -0.305470550606986, -0.310404246341246, -0.315968373406836, -0.320944907750239, -0.324079214224742, -0.324556574173249, -0.322112442597518, -0.316986966919491, -0.309799503139502, -0.301318199245306, -0.292268426851028, -0.283659285009973, -0.27671259375517, -0.272667704689424, -0.272190038239891, -0.275291284805382, -0.281719009551322, -0.290589519682213, -0.300310199166483, -0.30876120244271, -0.31438823820421, -0.316638190658425, -0.316118908804157, -0.314022886553781, -0.311718582466062, -0.310219128415795, -0.310128026393089, -0.311828599109319, -0.315278380721729, -0.319904784507483, -0.324846973506367, -0.329273468142693, -0.332371633417039, -0.330434140196889, -0.318700330890727, -0.288821023533946, -0.235028315333709, -0.163427937991548]


measurements = measurements[5:len(measurements)-5]
smooth = smooth[5:len(smooth)-5]

import charts

options = dict(
    height=1000, 
    title=dict(
    	text='Sensor'),
    	chart=dict(zoomType='xy')
	)




import pandas as pd
import numpy as np

smooth = pd.DataFrame(smooth)
measurements = pd.DataFrame(measurements)

res = pd.concat([smooth, measurements],axis=1,ignore_index=True)
print len(smooth), len(measurements)

charts.plot(res, options=options)

コード例 #17
0
ファイル: country.py プロジェクト: shiping998/crawler-list
area_list = []
for i in movie.find():
    area_list.append(i['content'])
area_index = list(set(area_list))
print(area_index)

post_times = []
for index in area_index:
    post_times.append(area_list.count(index))
print(post_times)


def data_gen(types):
    length = 0
    if length <= len(area_index):
        for area, times in zip(area_index, post_times):
            data = {'name': area, 'data': [times], 'type': types}
            yield data
            length += 1


data_gen('column')

for i in data_gen('column'):
    print(i)

series = [data for data in data_gen('column')]
charts.plot(series,
            show='inline',
            options=dict(title=dict(text='豆瓣电影top250出产国家和地区分析')))
コード例 #18
0
def ag_hgtj_company(p_base_data):
    '''
    A股的高管增持统计(根据公司)
    :return:
    '''
    CONST_TABLE_NAME = 'agzc'
    CONST_STOCK_NAME = "股票名称"
    CONST_SUM_COLUMN = '变动金额'
    p_base_data = p_base_data

    series = [{
        'type': 'column',
        'name': '增持金额',
        'data': [],
        "borderWidth": 0,
        "tooltip": {
            "headerFormat": '<span style="font-size:11px">{series.name}</span><br>',
            "pointFormat": '<span style="color:{point.color}">{point.name}</span>: <b>{point.y}百万</b> of total<br/>'
        },
        "dataLabels": {
            "enabled": True,
            "rotation": -90,
            "color": '#FFFFFF',
            "align": 'right',
            "format": '{point.y:.1f}',
            "y": -30
        }
    }]

    pdData = pd.read_sql("SELECT * from " + CONST_TABLE_NAME + " where 日期 > '" + CONST_BASE_DATE + "' ", conn)
    sumPdData = pdData.groupby(CONST_STOCK_NAME).sum()
    # sumPdData = sumPdData.sort_values(by=CONST_SUM_COLUMN, ascending=False).head(30)
    sumPdData = sumPdData.sort_values(by=CONST_SUM_COLUMN, ascending=False)
    sumPdData[CONST_SUM_COLUMN] = sumPdData[CONST_SUM_COLUMN].apply(lambda x: round(x / 1000000, 2))
    df1 = ts.get_stock_basics()
    # list1 = sumPdData.index.tolist()
    # pd2 = df1[df1['name'].isin(list1)].sort_values(by='pe', ascending=False)
    sumPdData = sumPdData.reset_index()
    sumPdData = pd.merge(sumPdData, df1, how='inner', left_on=[CONST_STOCK_NAME], right_on=['name'])
    sumPdData = sumPdData[(sumPdData['pe'] < 35) & (sumPdData[CONST_SUM_COLUMN] > 1)].head(30)
    IPython.core.display.publish_display_data({'text/html': (sumPdData[['name', 'pe', 'industry', 'timeToMarket', CONST_SUM_COLUMN]]).to_html()})
    sumPdData = sumPdData.set_index(CONST_STOCK_NAME)
    options = {
        'title': {'text': '回购统计_公司'},
        'subtitle': {'text': ''},
        "xAxis": {
            "type": 'category',
            "crosshair": True
        },
        "yAxis": {
            # "min": 0,
            "title": {
                "text": '金额 (百万)'
            }
        }
    }
    totalHgMoney = []
    for key, value in sumPdData[CONST_SUM_COLUMN].to_dict().items():
        totalHgMoney.append([key, value])
    series[0]['data'] = totalHgMoney
    IPython.core.display.publish_display_data({'text/html': charts.plot(series, options=options, show='inline').data})
コード例 #19
0
# In[ ]:

hp = houseprint.Houseprint()
hp.init_tmpo()


# In[ ]:

start = pd.Timestamp(time.time() - number_of_days*86400, unit='s')


# In[ ]:

sensors = hp.get_sensors()
#sensors.remove('b325dbc1a0d62c99a50609e919b9ea06')


# In[ ]:

for sensor in sensors:
    s = sensor.get_data(head=start)
    try:    
        # plot with charts (don't show it) and save html
        charts.plot(pd.DataFrame(s), stock=True, 
                    save=os.path.join(c.get('data', 'folder'), 'figures', 'TimeSeries_'+sensor.key+'.html'), show=False)
    except Exception as e:
        print(e)



コード例 #20
0
ファイル: graph.py プロジェクト: nihaozjf/crawler
    items =item_info.aggregate(pipeline)
    return items
def draw_one_day_items(day):
    data=[]
    for item in  get_one_day_items(day):

        if item['_id']!=None:
            if len(item['_id'])==0:
                item['_id']=['unkown']
            data.append([item['_id'][0],item['counts']])
    #print data
    series={
        'type':'pie',
        'name':'pie chart',
        'data':data

    }
    return series
if __name__=='__main__':
    #print 'start'
    #items =get_all_post('2016.01.12','2016.01.12',['\u5317\u4eac\u4e8c\u624b\u5bb6\u7535'])
    #series=[i for i in get_all_post('2016.01.12','2016.01.19',['北京二手家电','北京二手手机','北京二手笔记本'])]

    #charts.plot(series,show='window')
    #print 'end'
    series=draw_one_day_items('2015.12.29')
    print series
    charts.plot(series,show='window')


コード例 #21
0
ファイル: bar_chart.py プロジェクト: adorn331/CrawlerToy
citys_data = [(i,data_collection.find({'area':i}).count()) for i in citys]
#构造各个城市的对应发帖数量的元组列表
citys_data = sorted(citys_data, key=lambda x:x[1], reverse=True)
#将其排序
#######


#进行柱状图展示前十名的城市
series = [{
    'name':i[0],
    'data':[i[1]],
    'type':'column',
} for i in citys_data[:20] ]

#charts.plot(series, show='inline')
charts.plot(series, show='inline', options=dict(title=dict(text='武汉赶集网帖子发布地区分布前10')))



for i in data_collection.find({'area':'北京'}, {'cates':1, '_id':0, 'pub_date':1}).limit(300):
    print(i)
    #find的参数:第一个字典是查找,第二个是显示的数据项,0代表不显示

#手动输入效果
# series = [
#     {
#     'name': 'OS X',
#     'data': [11],
#     'type': 'column'
# }, {
#     'name': 'Ubuntu',
コード例 #22
0
#示例用charts(highcharts)做数据分析
import pymongo,json,charts


client = pymongo.MongoClient('localhost')
db = client['QQbuluo']
bars_info = db['barlist']
series=[]
#下面是从明沟db中取数据,并格式化成highcharts所需的数据结构
for bar_info in bars_info.find({'category':12,'fans':{'$gt':500000}},{'name':1,'fans':1,'_id':0}):
    bar_data={
        'name':bar_info['name'],
        'data':[bar_info['fans']],
        'type':'column'
    }
    series.append(bar_data)
#print(series)
charts.plot(series,options=dict(title=dict(text='QQ部落粉丝大于50w的城市'),show='inline'))
コード例 #23
0
                count_all.append(all_date['cates'][2])      #取得所有数据类目 归入到类目列表里

            count_data.append(count_all.count(cate))        #用类目列表统计类目出现次数   求出 某一天某一个类目发帖次数


        data ={
                    'name':cate,                            #根据第一层类目循环获取类目
                    'data':count_data,                      #从次数列表获取
                    'types':types,                          #图表类型 默认是line

            }

        yield data                  #返回data
#--------------------------------------------------------------------#
options = {
    'chart'  : {'zoomType':'xy'},
    'title'  : {'text':'发帖量统计'},
    'subtitle':{'text':'可视化统计图表'},
    'xAxis'  : {'categories':[i for i in get_time('2016.01.01','2016.01.07')]},
    'yAxis'  : {'title':{'text':'数量'}}
}
series = [i for i in get_all_info('2016.01.01','2016.01.07',['北京二手手机','北京二手台式机/配件','北京二手笔记本'])]
charts.plot(series,options=options,show='inline')
#===================================================================#

# for循环用多了,头疼  一层层认真检查 以免乱了
# 作业总结 1.貌似mongodb数据库查询中 $in条件后面 日期格式 必须是 2016-01-01这种 换成2016.01.01有的能查到有的查不到
#          不知道别人是怎么弄的 我是在这儿卡了半天
#          2.注意chart  series = [{'name'= xxx,'data'=[x,x,x,x],'type'=type}]这个格式
#          注意在函数中我们生成的data 不用加[] 后期列表推导式[x for x in get_all_info]会自动生成[] 这个只能怪自己没认真检查
コード例 #24
0
ファイル: main.py プロジェクト: kidultfan/src
def processInfo(info, para):
    """
    信息存储
    """
    text = ''

    word_lst = []
    series1 = [{
        'type':
        'pie',
        'name':
        '浏览器访问量占比',
        'data': [
            #         ['Firefox', 45.0],
            #         ['IE', 26.8],
            # ['Safari', 8.5],
            # ['Opera', 6.2],
        ]
    }]
    logging.error('Process start')
    try:
        writer.writerow([
            '公司名称', '公司类型', '融资阶段', '标签', '公司规模', '公司所在地', '职位类型', '职位要求',
            '学历要求', '福利', '薪资', '工作经验'
        ])
        for p in info:
            text = text + str(p['content'])
            word_lst.append(str(p['positionSalary']))
            writer.writerow([
                str(p['companyName']),
                str(p['companyType']),
                str(p['companyStage']),
                str(p['companyLabel']),
                str(p['companySize']),
                str(p['companyDistrict']),
                str(p['positionType']),
                str(p['content']),
                str(p['positionEducation']),
                str(p['positionAdvantage']),
                str(p['positionSalary']),
                str(p['positionWorkYear'])
            ])
        csvfile.close()
        seg_list = jieba.cut(text, cut_all=False)
        tags = jieba.analyse.extract_tags(text, topK=50)
        # type = chardet.detect("".join(seg_list))
        # text1 = text.decode(type["encoding"])
        for item in word_lst:
            if item not in word_dict:
                word_dict[item] = 1
            else:
                word_dict[item] += 1
        for key, value in word_dict.items():
            series1[0]['data'].append(
                [key, value * 100 / word_lst.__len__()], )
            #                             )
            series.append({
                'name': key,
                'data': [value],
                'type': 'column',
            })
        charts.plot(series1, options=dict(title=dict(text='薪资分布!!!')))

        # charts.plot(series,options=dict(title=dict(text='Charts is awesome!!!')))

        print "\"%s\":\"%s\"" % (key, value / word_dict.__len__() * 100)

        print key, value * 100 / word_lst.__len__()
        print("Default Mode: " + "/ ".join(seg_list))  # 精确模式
        # print (text)
        # text=jiebaclearText(text)
        print("Default Mode: " + "/ ".join(tags))  # 精确模式
        font_path = '肥肥扭扭体.ttf'
        wordcloud = WordCloud(background_color='white',
                              font_path=font_path,
                              scale=1.5).generate(text)

        #显示词云图片

        plt.imshow(wordcloud)
        plt.axis('off')
        plt.show()

        return True
    except Exception as e:
        print(e)
        return None
コード例 #25
0
    'chart': {
        'zoomType': 'xy'
    },
    'title': {
        'text': '2015-12-26淮阴工学院学生整体网页浏览分布'
    },
    'tooltip': {
        'headerFormat': '{series.name}<br>',
        'pointFormat': '{point.name}: <b>{point.percentage:.1f}%</b>'
    },
    'plotOptions': {
        'pie': {
            'allowPointSelect': True,
            'cursor': 'pointer',
            'dataLabels': {
                'enabled': True,
                'format': '<b>{point.name}</b>: {point.percentage:.1f} %',
            }
        }
    },
}
nbm_series = [{
    'type':
    'pie',
    'name':
    'pie chart',
    'data': [["文化教育", education], ["生活服务", service], ["电脑网络", computer],
             ["娱乐休闲", entertainment], ["其他", other]]
}]
charts.plot(nbm_series, options=nbm_options)
コード例 #26
0
            data = {
                'name':area,
                'data':[times],
                'type':types
            }
            yield data
            length += 1


# In[42]:

data_gen('column')


# In[44]:

for i in data_gen('column'):
    print(i)


# In[45]:

series = [data for data in data_gen('column')]
charts.plot(series, show='inline',options=dict(title=dict(text='北京城区二手物品发帖量')))


# In[ ]:



コード例 #27
0
ファイル: charts_0.1 .py プロジェクト: qchs/58

# In[74]:

def date_gen(type):
    length = 0
    if length <= len(catelog):
        for cates,times in zip(catelog,post_times):
            data = {
                'name':cates,
                'data':[times],
                'type':type
            }
            yield data
#             print(data)
            length += 1
            
series = [i for i in date_gen('column')]
print(series)


# In[75]:

charts.plot(series,show = 'inline',options = dict(title= dict(text = 'aaa')))


# In[ ]:



コード例 #28
0
import charts

data = [[1,8],[2,7],[3,4],[4,3],[5,9],[6,0],[7,10],[8,5]]

charts.plot(data,name = 'Second list data',show = 'inline',options=dict(title = dict(text='My second chart!')))