爬蟲數據可視化

使用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)

可視化結果spa

相關文章
相關標籤/搜索