99999久久久久久亚洲,欧美人与禽猛交狂配,高清日韩av在线影院,一个人在线高清免费观看,啦啦啦在线视频免费观看www

熱線電話:13121318867

登錄
首頁精彩閱讀太炫酷了,這里有一個用于制作數(shù)據(jù)面板大屏的Python模塊
太炫酷了,這里有一個用于制作數(shù)據(jù)面板大屏的Python模塊
2022-05-07
收藏

作者:俊欣

來源:關(guān)于數(shù)據(jù)分析與可視化

Python當(dāng)中用于繪制圖表的模塊,相信大家用的最多的便是matplotlibseabron,除此之外還有一些用于動態(tài)交互的例如Plotly模塊和Pyecharts模塊,今天小編再為大家來推薦兩個用于制作可視化大屏的庫,分別叫做hvPlot以及Panel,在本篇教程當(dāng)中,小編依次會為大家分享

  • pandas以及hvPlot結(jié)合生成具有交互性的圖表
  • Panel模塊生成小的組件,配合圖表進(jìn)行使用
  • 制作一個數(shù)據(jù)可視化大屏來更好地呈現(xiàn)數(shù)據(jù)

pandas+hvPlot繪制圖表

我們首先導(dǎo)入一些要用到的模塊以及用pandas來讀取數(shù)據(jù)集,代碼如下

# To handle data import numpy as np import pandas as pd # To make visualizations import hvplot.pandas import panel as pn; pn.extension() from panel.template import DarkTheme

pandas繪制出來的圖表默認(rèn)都是以matplotlib模塊為后端,因?yàn)椴痪邆浣换バ?,如下圖所示

sales = pd.read_csv('games_sales.csv')
sales.plot(kind='line', x='Year', y='Units sold(in millions)', color='orange', grid=True, title='Pokémon Game Sales');

output

太炫酷了,這里有一個用于制作數(shù)據(jù)面板大屏的Python模塊

代碼中的kind參數(shù)對應(yīng)的是圖表的類型,X參數(shù)代表的是X軸上面的所要要用到的數(shù)據(jù),同理,我們還指定了標(biāo)題、圖表的顏色等等參數(shù),那么要是我們希望pandas在繪制圖表的時候是以hvPlot為后端,需要添加如下的代碼

pd.options.plotting.backend = 'holoviews' 

我們同樣來繪制如上所示的圖表,代碼如下

sales.plot(kind='line', x='Year', y='Units sold(in millions)', color='orange', grid=True, title='Pokémon Game Sales')

output

太炫酷了,這里有一個用于制作數(shù)據(jù)面板大屏的Python模塊

通過最右側(cè)的工具欄,我們可以將繪制出來的圖表保存、放大/縮小、移動等一系列操作。我們也可以同時將若干種圖表結(jié)合在一起,繪制在同一張圖上面

salesplot = sales.plot(kind='line', x='Year', y='Units sold(in millions)',
                       color='orange', grid=True, title='Pokémon Game Sales',
                       hover=False) * 
                sales.plot(kind='scatter', x='Year', y='Units sold(in millions)',
                           color='#c70000', hover_cols='Game')
salesplot

output

太炫酷了,這里有一個用于制作數(shù)據(jù)面板大屏的Python模塊

我們分別繪制了兩張圖表,散點(diǎn)圖以及折線圖,通過*將兩者有效地結(jié)合到了一塊兒。

制作一個小組件

在上一期小編寫過的教程

【干貨原創(chuàng)】介紹一個Python模塊,Seaborn繪制的圖表也能實(shí)現(xiàn)動態(tài)交互

里面提到用ipywidgets模塊來制作并且生成組件配合著可視化圖表來使用,這次我們用Panel模塊也來生成一個類似的組件,代碼如下

pok_types = list(df.type_1.unique())
pok_type = pn.widgets.Select(name='Type', options=pok_types)
pok_type

output

太炫酷了,這里有一個用于制作數(shù)據(jù)面板大屏的Python模塊

我們結(jié)合該組件來繪制圖表,代碼如下

viz0 = data_pipeline[['pokedex_number', 'name',
                      'total_points']].hvplot(kind='table',title='Pokémons',
                                              width=400, height=400)
viz0

output

太炫酷了,這里有一個用于制作數(shù)據(jù)面板大屏的Python模塊

我們可以通過當(dāng)中的參數(shù)kind來調(diào)整要繪制的圖表的類型,width以及height參數(shù)來調(diào)整圖表的大小,title參數(shù)來調(diào)整圖表的標(biāo)題,我們來繪制一張散點(diǎn)圖,代碼如下

viz1 = data_pipeline.hvplot(x='weight_kg', y='height_m', by='type_2', kind='scatter', 
                     hover_cols=['name', 'type_1', 'type_2'],
                     width=600, height=400,grid=True,
                     title='Relationship between Weight (kg) and Height (m), by Type' )
viz1

output

太炫酷了,這里有一個用于制作數(shù)據(jù)面板大屏的Python模塊

另外我們也可以同樣來繪制一張柱狀圖,代碼如下

data_damage = data_pipeline.iloc[:, -18:].mean().rename('Damage')
viz2 = data_damage.hvplot(kind='bar',c='Damage', 
               title='正在思考要取什么標(biāo)題會比較好......', 
               rot=30, shared_axes=False,
               colorbar=True, colormap='RdYlGn_r', 
               )
viz2

output

太炫酷了,這里有一個用于制作數(shù)據(jù)面板大屏的Python模塊

制作一個數(shù)據(jù)面板大屏

接下來我們將上面繪制的所有圖表,都放置在一張數(shù)據(jù)大屏當(dāng)中顯示,代碼如下

template = pn.template.FastListTemplate(theme=DarkTheme,
    title = '數(shù)據(jù)面板',
    sidebar=[
        pn.pane.Markdown('# 關(guān)于這個項(xiàng)目'),
        pn.pane.Markdown('#### 這個項(xiàng)目的數(shù)據(jù)來源是[Kaggle](https://www.kaggle.com/datasets/mariotormo/complete-pokemon-dataset-updated-090420) and on [Wikipedia](https://en.wikipedia.org/wiki/Pok%C3%A9mon_(video_game_series)#Reception) about Pokémons to explore different types of visualizations using HoloViz tools: [Panel](https://panel.holoviz.org/) [hvPlot](https://hvplot.holoviz.org/)'),
        pn.pane.JPG('圖片的路徑.jpg', sizing_mode='scale_both'),
        pn.pane.Markdown('[圖片的來源](https://unsplash.com/photos/dip9IIwUK6w)'),
        pn.pane.Markdown('## Filter by Type'),
        pok_type
    ],
    main=[pn.Row(
                  pn.Column(viz0.panel(width=600, height=400, margin=(0,20))), 
                  pn.Column(pn.Row(viz1.panel(width=700, height=250, margin=(0,20))),
                            pn.Column(viz2.panel(width=700, height=250), margin=(0,20))),
                 ),
          pn.Row(salesplot.opts(width=1400, height=200))
    ],
    accent_base_color='#d78929',
    header_background='#d78929',
    sidebar_footer='<br><br><a href=".......">GitHub鏈接</a>', 
    main_max_width='100%' )

template.servable();

template.show()

output

Launching server at http://localhost:63968 <bokeh.server.server.Server at 0x1bd811e82b0> 

我們按照上述的鏈接來瀏覽器中打開,數(shù)據(jù)大屏面板就可以做好了,如下圖所示

太炫酷了,這里有一個用于制作數(shù)據(jù)面板大屏的Python模塊

數(shù)據(jù)分析咨詢請掃描二維碼

若不方便掃碼,搜微信號:CDAshujufenxi

數(shù)據(jù)分析師資訊
更多

OK
客服在線
立即咨詢
客服在線
立即咨詢
') } function initGt() { var handler = function (captchaObj) { captchaObj.appendTo('#captcha'); captchaObj.onReady(function () { $("#wait").hide(); }).onSuccess(function(){ $('.getcheckcode').removeClass('dis'); $('.getcheckcode').trigger('click'); }); window.captchaObj = captchaObj; }; $('#captcha').show(); $.ajax({ url: "/login/gtstart?t=" + (new Date()).getTime(), // 加隨機(jī)數(shù)防止緩存 type: "get", dataType: "json", success: function (data) { $('#text').hide(); $('#wait').show(); // 調(diào)用 initGeetest 進(jìn)行初始化 // 參數(shù)1:配置參數(shù) // 參數(shù)2:回調(diào),回調(diào)的第一個參數(shù)驗(yàn)證碼對象,之后可以使用它調(diào)用相應(yīng)的接口 initGeetest({ // 以下 4 個配置參數(shù)為必須,不能缺少 gt: data.gt, challenge: data.challenge, offline: !data.success, // 表示用戶后臺檢測極驗(yàn)服務(wù)器是否宕機(jī) new_captcha: data.new_captcha, // 用于宕機(jī)時表示是新驗(yàn)證碼的宕機(jī) product: "float", // 產(chǎn)品形式,包括:float,popup width: "280px", https: true // 更多配置參數(shù)說明請參見:http://docs.geetest.com/install/client/web-front/ }, handler); } }); } function codeCutdown() { if(_wait == 0){ //倒計時完成 $(".getcheckcode").removeClass('dis').html("重新獲取"); }else{ $(".getcheckcode").addClass('dis').html("重新獲取("+_wait+"s)"); _wait--; setTimeout(function () { codeCutdown(); },1000); } } function inputValidate(ele,telInput) { var oInput = ele; var inputVal = oInput.val(); var oType = ele.attr('data-type'); var oEtag = $('#etag').val(); var oErr = oInput.closest('.form_box').next('.err_txt'); var empTxt = '請輸入'+oInput.attr('placeholder')+'!'; var errTxt = '請輸入正確的'+oInput.attr('placeholder')+'!'; var pattern; if(inputVal==""){ if(!telInput){ errFun(oErr,empTxt); } return false; }else { switch (oType){ case 'login_mobile': pattern = /^1[3456789]\d{9}$/; if(inputVal.length==11) { $.ajax({ url: '/login/checkmobile', type: "post", dataType: "json", data: { mobile: inputVal, etag: oEtag, page_ur: window.location.href, page_referer: document.referrer }, success: function (data) { } }); } break; case 'login_yzm': pattern = /^\d{6}$/; break; } if(oType=='login_mobile'){ } if(!!validateFun(pattern,inputVal)){ errFun(oErr,'') if(telInput){ $('.getcheckcode').removeClass('dis'); } }else { if(!telInput) { errFun(oErr, errTxt); }else { $('.getcheckcode').addClass('dis'); } return false; } } return true; } function errFun(obj,msg) { obj.html(msg); if(msg==''){ $('.login_submit').removeClass('dis'); }else { $('.login_submit').addClass('dis'); } } function validateFun(pat,val) { return pat.test(val); }