Python 可視化神器Plotly詳解
文 | 潮汐
來(lái)源:Python 技術(shù)「ID: pythonall」
學(xué)習(xí)Python是做數(shù)分析的最基礎(chǔ)的一步,數(shù)據(jù)分析離不開數(shù)據(jù)可視化。Python第三方庫(kù)中我們最常用的可視化庫(kù)是 pandas,matplotlib,pyecharts, 當(dāng)然還有 Tableau,另外最近在學(xué)習(xí)過(guò)程中發(fā)現(xiàn)另一款可視化神器-Plotly,它是一款用來(lái)做數(shù)據(jù)分析和可視化的在線平臺(tái),功能非常強(qiáng)大, 可以在線繪制很多圖形比如條形圖、散點(diǎn)圖、餅圖、直方圖等等。除此之外,它還支持在線編輯,以及多種語(yǔ)言 python、javascript、matlab、R等許多API。它在python中使用也非常簡(jiǎn)單,直接用pip install plotly 安裝好即可使用。本文將結(jié)合 plotly 庫(kù)在 jupyter notebook 中來(lái)進(jìn)行圖形繪制。
使用 Plotly 可以畫出很多媲美Tableau的高質(zhì)量圖,如下圖所示:
折現(xiàn)點(diǎn)圖畫圖步驟如下:首先在 Pycharm 界面輸入 jupyter notebook后進(jìn)入網(wǎng)頁(yè)編輯界面,新建一個(gè)文件,導(dǎo)入相應(yīng)的包即可進(jìn)行圖形繪制:
# import pkgfrom plotly.graph_objs import Scatter,Layoutimport plotlyimport plotly.offline as pyimport numpy as npimport plotly.graph_objs as go
#設(shè)置編輯模式plotly.offline.init_notebook_mode(connected=True)
#制作折線圖N = 150random_x = np.linspace(0,1,N)random_y0 = np.random.randn(N)+7random_y1 = np.random.randn(N)random_y2 = np.random.randn(N)-7 trace0 = go.Scatter( x = random_x, y = random_y0, mode = ’markers’, name = ’markers’)trace1 = go.Scatter( x = random_x, y = random_y1, mode = ’lines+markers’, name = ’lines+markers’)trace2 = go.Scatter( x = random_x, y = random_y2, mode = ’lines’, name = ’lines’)data = [trace0,trace1,trace2]py.iplot(data)
顯示結(jié)果如下:
# 直方圖trace0 = go.Bar( x = [’Jan’,’Feb’,’Mar’,’Apr’, ’May’,’Jun’, ’Jul’,’Aug’,’Sep’,’Oct’,’Nov’,’Dec’], y = [20,15,25,16,18,28,19,67,12,56,14,27], name = ’Primary Product’, marker=dict( color = ’rgb(49,130,189)’ ))trace1 = go.Bar( x = [’Jan’,’Feb’,’Mar’,’Apr’, ’May’,’Jun’, ’Jul’,’Aug’,’Sep’,’Oct’,’Nov’,’Dec’], y = [29,14,32,14,16,19,25,14,10,12,82,16], name = ’Secondary Product’, marker=dict( color = ’rgb(204,204,204)’ ))data = [trace0,trace1]py.iplot(data)
顯示結(jié)果如下:
散點(diǎn)圖
# 散點(diǎn)圖trace1 = go.Scatter( y = np.random.randn(700), mode = ’markers’, marker = dict( size = 16, color = np.random.randn(800), colorscale = ’Viridis’, showscale = True ))data = [trace1]py.iplot(data)
顯示結(jié)果如下:
今天的文章主要學(xué)習(xí)可視化神器-plotpy 的相關(guān)操作,希望在平時(shí)的工作中有所應(yīng)用。更多的內(nèi)容詳見 https://plotly.com/python/
到此這篇關(guān)于Python 可視化神器Plotly詳解的文章就介紹到這了,更多相關(guān)Python 可視化神器Plotly內(nèi)容請(qǐng)搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
相關(guān)文章:
1. vue跳轉(zhuǎn)頁(yè)面常用的幾種方法匯總2. XML 非法字符(轉(zhuǎn)義字符)3. CSS3實(shí)例分享之多重背景的實(shí)現(xiàn)(Multiple backgrounds)4. XML入門的常見問(wèn)題(三)5. 不要在HTML中濫用div6. ASP動(dòng)態(tài)include文件7. 父div高度不能自適應(yīng)子div高度的解決方案8. asp createTextFile生成文本文件支持utf89. Jquery使用原生AJAX方法請(qǐng)求數(shù)據(jù)10. el-input無(wú)法輸入的問(wèn)題和表單驗(yàn)證失敗問(wèn)題解決
