爬蟲數據可視化


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

可視化結果

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM