您好,登錄后才能下訂單哦!
這篇文章主要講解了“怎么用Python matplotlib plotly繪制圖表”,文中的講解內(nèi)容簡(jiǎn)單清晰,易于學(xué)習(xí)與理解,下面請(qǐng)大家跟著小編的思路慢慢深入,一起來(lái)研究和學(xué)習(xí)“怎么用Python matplotlib plotly繪制圖表”吧!
以300部電影作為數(shù)據(jù)源
import pandas as pd cnboo=pd.read_excel("cnboNPPD1.xls")
cnboo
import seaborn as sns import numpy as np import matplotlib as mpl from matplotlib import pyplot as plt import pandas as pd from datetime import datetime,timedelta %matplotlib inline plt.rcParams['font.sans-serif']=['SimHei'] # 用來(lái)正常顯示中文標(biāo)簽 plt.rcParams['axes.unicode_minus']=False # 用來(lái)正常顯示負(fù)號(hào) from datetime import datetime
! pip install plotly # 安裝 import matplotlib.pyplot as plt import plotly from plotly.offline import download_plotlyjs,init_notebook_mode,plot,iplot
x=cnboo['BO'].tolist() y=cnboo['PERSONS'].tolist() dict01={"x":x,"y":y} dict01
# 折線圖 iplot([dict01])
import plotly.graph_objs as go iplot([go.Scatter(x=x,y=y,mode='markers')])
# 隨機(jī)生成的點(diǎn)圖 import numpy as np iplot([go.Scatter(x=np.random.randn(100),y=np.random.randn(100),mode='markers')])
go
trace=go.Scatter(x=cnboo['PRICE'],y=y,mode='markers',) data=[trace] iplot(data)
trace=go.Scatter(x=cnboo['PRICE'],y=y,mode='markers',marker=dict(color='red',size=9,opacity=0.4)) data=[trace] iplot(data)
colors=['#dc2624','#2b4750','#45a0a2','#e87a59','#7dcaa9','#649E7D','#dc8018', '#C89F91','#6c6d6c','#4f6268','#c7cccf']
filmtype=cnboo['TYPE'] filmbo=cnboo['PRICE'] trace=go.Pie(labels=filmtype,values=filmbo, hoverinfo='label+percent',textinfo='value',textfont=dict(size=10), marker=dict(colors=colors,line=dict(color='#000000',width=3))) data=[trace]
iplot(data)
filmtype=cnboo['TYPE'] filmbo=cnboo['PRICE'] trace=go.Pie(labels=filmtype,values=filmbo, hoverinfo='label+percent',textinfo='value',textfont=dict(size=12), marker=dict(colors=colors)) data=[trace] iplot(data)
# plotly bar trace1=go.Bar(x=cnboo['TYPE'],y=cnboo['PRICE'],name="類(lèi)型與票價(jià)") trace2=go.Bar(x=cnboo['TYPE'],y=y,name="類(lèi)型與人數(shù)") layout=go.Layout(title="中國(guó)電影類(lèi)型與票價(jià),人數(shù)的關(guān)系",xaxis=dict(title='電影類(lèi)型')) data=[trace1,trace2] fig=go.Figure(data,layout=layout) iplot(fig)
trace1=go.Scatter(x=cnboo['TYPE'],y=cnboo['PRICE'],name="類(lèi)型與票價(jià)",mode="markers", marker=dict(color="red",size=8)) trace2=go.Scatter(x=cnboo['TYPE'],y=cnboo['PERSONS'],name="類(lèi)型與人數(shù)",mode="markers", marker=dict(color="blue",size=5)) data=[trace1,trace2] iplot(data)
trace1=go.Scatter(x=cnboo['TYPE'],y=cnboo['PRICE'],name="類(lèi)型與票價(jià)",mode="markers", marker=dict(color="red",size=8)) trace2=go.Scatter(x=cnboo['TYPE'],y=cnboo['PERSONS'],name="類(lèi)型與人數(shù)",mode="markers", marker=dict(color="blue",size=5)) layout=go.Layout(title="中國(guó)電影類(lèi)型與票價(jià),人數(shù)的關(guān)系",plot_bgcolor="#FFFFFF") data=[trace1,trace2] fig=go.Figure(data,layout=layout) iplot(fig)
import plotly.figure_factory as ff
fig=ff.create_2d_density(x,y,colorscale=colors,hist_color='#dc2624',point_size=5) iplot(fig,filename='評(píng)分與人次')
colorscale=['rgb(20, 38, 220)', 'rgb(255, 255, 255)'] # 最后一個(gè)顏色都是調(diào)用背景
fig=ff.create_2d_density(x,y,colorscale=colorscale,hist_color='#dc2624',point_size=5) iplot(fig,filename='評(píng)分與人次')
layout=go.Layout(title="中國(guó)電影票房與人次,票價(jià)的關(guān)系",barmode="group")
trace01=go.Scatter3d( x=cnboo['BO'], y=cnboo['PRICE'], z=cnboo['PERSONS'], mode='markers', marker=dict(size=12,color=colors,colorscale='Viridis', opacity=0.5,showscale=True) #opacity是透明度 )
data=[trace01] fig=go.Figure(data=data,layout=layout) iplot(fig,filename='3d')
感謝各位的閱讀,以上就是“怎么用Python matplotlib plotly繪制圖表”的內(nèi)容了,經(jīng)過(guò)本文的學(xué)習(xí)后,相信大家對(duì)怎么用Python matplotlib plotly繪制圖表這一問(wèn)題有了更深刻的體會(huì),具體使用情況還需要大家實(shí)踐驗(yàn)證。這里是億速云,小編將為大家推送更多相關(guān)知識(shí)點(diǎn)的文章,歡迎關(guān)注!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。