Radar charts in Python - Plotly

文章推薦指數: 80 %
投票人數:10人

A Radar Chart (also known as a spider plot or star plot) displays multivariate data in the form of a two-dimensional chart of quantitative variables represented ... Forum Pricing Dash QuickReference GettingStarted IsPlotlyFree? FigureReference APIReference Dash GitHub community.plotly.com OnThisPage ARadarChart(alsoknownasaspiderplotorstarplot)displaysmultivariatedataintheformofatwo-dimensionalchartofquantitativevariablesrepresentedonaxesoriginatingfromthecenter.Therelativepositionandangleoftheaxesistypicallyuninformative.Itisequivalenttoaparallelcoordinatesplotwiththeaxesarrangedradially. ForaRadarChart,useapolarchartwithcategoricalangularvariables,withpx.line_polar,orwithgo.Scatterpolar.Seemoreexamplesofpolarcharts. RadarChartwithPlotlyExpress¶PlotlyExpressistheeasy-to-use,high-levelinterfacetoPlotly,whichoperatesonavarietyoftypesofdataandproduceseasy-to-stylefigures. Useline_close=Trueforclosedlines. In [1]: importplotly.expressaspx importpandasaspd df=pd.DataFrame(dict( r=[1,5,2,2,3], theta=['processingcost','mechanicalproperties','chemicalstability', 'thermalstability','deviceintegration'])) fig=px.line_polar(df,r='r',theta='theta',line_close=True) fig.show() ForafilledlineinaRadarChart,updatethefigurecreatedwithpx.line_polarwithfig.update_traces. In [2]: importplotly.expressaspx importpandasaspd df=pd.DataFrame(dict( r=[1,5,2,2,3], theta=['processingcost','mechanicalproperties','chemicalstability', 'thermalstability','deviceintegration'])) fig=px.line_polar(df,r='r',theta='theta',line_close=True) fig.update_traces(fill='toself') fig.show() BasicRadarChartwithgo.Scatterpolar¶ In [3]: importplotly.graph_objectsasgo fig=go.Figure(data=go.Scatterpolar( r=[1,5,2,2,3], theta=['processingcost','mechanicalproperties','chemicalstability','thermalstability', 'deviceintegration'], fill='toself' )) fig.update_layout( polar=dict( radialaxis=dict( visible=True ), ), showlegend=False ) fig.show() MultipleTraceRadarChart¶ In [4]: importplotly.graph_objectsasgo categories=['processingcost','mechanicalproperties','chemicalstability', 'thermalstability','deviceintegration'] fig=go.Figure() fig.add_trace(go.Scatterpolar( r=[1,5,2,2,3], theta=categories, fill='toself', name='ProductA' )) fig.add_trace(go.Scatterpolar( r=[4,3,2.5,1,2], theta=categories, fill='toself', name='ProductB' )) fig.update_layout( polar=dict( radialaxis=dict( visible=True, range=[0,5] )), showlegend=False ) fig.show() Reference¶Seefunctionreferenceforpx.(line_polar)orhttps://plotly.com/python/reference/scatterpolar/formoreinformationandchartattributeoptions! WhatAboutDash?¶Dashisanopen-sourceframeworkforbuildinganalyticalapplications,withnoJavascriptrequired,anditistightlyintegratedwiththePlotlygraphinglibrary. LearnabouthowtoinstallDashathttps://dash.plot.ly/installation. Everywhereinthispagethatyouseefig.show(),youcandisplaythesamefigureinaDashapplicationbypassingittothefigureargumentoftheGraphcomponentfromthebuilt-indash_core_componentspackagelikethis: importplotly.graph_objectsasgo#orplotly.expressaspx fig=go.Figure()#oranyPlotlyExpressfunctione.g.px.bar(...) #fig.add_trace(...) #fig.update_layout(...) importdash importdash_core_componentsasdcc importdash_html_componentsashtml app=dash.Dash() app.layout=html.Div([ dcc.Graph(figure=fig) ]) app.run_server(debug=True,use_reloader=False)#TurnoffreloaderifinsideJupyter ×



請為這篇文章評分?