爬虫数据可视化

使用plotly,将爬虫获取的数据可视化,代码如下

import plotly.offline as py
from plotly.graph_objs import Scatter, Layout
import plotly.graph_objs as go
import pandas as pd
data = pd.read_csv('2018-05-27.csv')#载入数据
data.rename(columns = {'Unnamed: 0':'Name'},inplace=True)#rename index列

data = data[data['win_rate']>0.5]
data = data[data['select_num']>50]#获取胜率超过0.5且挑选超过50的数据
#创建柱状图
im = go.Bar(
    x = data['Name'],#x轴
    y = data['win_rate'],#y轴
    marker =dict(
        color = data['select_num'],#颜色跟随
        # size = data['select_num'],
        colorscale = 'Reds',#选择色系
        colorbar = dict(title = 'SelectTimes'),#colorbar添加title
        showscale = True#现实colorbar
    )
)
layout = go.Layout(#调整布局
    title = 'The hotest heros',
    autosize = False ,
    width = 1500,
    height = 600,
    xaxis = dict(title = 'Heros'),
    yaxis = dict(title = 'Rate of win'),
)
fig = go.Figure(data = [im],layout =layout)
py.plot(fig)

可视化结果

 

posted @ 2018-05-27 21:01  RokiChen  阅读(1498)  评论(0编辑  收藏  举报