1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > python 3d气泡图 python 3d 散点图

python 3d气泡图 python 3d 散点图

时间:2023-04-12 05:41:04

相关推荐

python 3d气泡图 python 3d 散点图

废话不说直接上代码:

%matplotlib inlineimport numpy as npimport io,pandas as pdimport matplotlib.pyplot as pltmyString='''类别订单量占比门店数占比交易额占比小龙虾0.60.91.7川湘菜4.54.86.5烤串2.94.54.8面馆3.88.03.1包子/粥6.33.54.7西式快餐7.97.59.2快餐简餐22.116.318.8'''df = pd.read_csv(io.StringIO(myString), sep='')df[['订单量占比','门店数占比','交易额占比']] = df[['订单量占比','门店数占比','交易额占比']].applymap(lambda x:pd.to_numeric(x))import plotly.graph_objects as goplanets = list(df['类别'])planet_colors = ['rgb(135, 135, 125)', 'rgb(210, 50, 0)', 'rgb(50, 90, 255)','rgb(178, 0, 0)', 'rgb(235, 235, 210)', 'rgb(235, 205, 130)','rgb(55, 255, 217)']x = list(df['订单量占比'])y = list(df['门店数占比'])z = list(df['交易额占比'])planet_diameter = list(df['订单量占比']*10000)# Create trace, sizing bubbles by planet diameterfig = go.Figure(data=go.Scatter3d(x = x,y = y,z = z,text = planets,mode = 'markers',marker = dict(sizemode = 'diameter',sizeref = 750, # info on sizeref: /python/reference/scatter/#scatter-marker-sizerefsize = planet_diameter,color = planet_colors,)))fig.update_layout(width=1400, height=1200, title = 'Planets!',scene = dict(xaxis=dict(title='订单量占比', titlefont_color='white'),yaxis=dict(title='门店数占比', titlefont_color='white'),zaxis=dict(title='交易额占比', titlefont_color='white'),bgcolor = 'rgb(140, 140, 170)'))fig.show()

效果如下:

告辞

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。