Radar Chart Using Python Plotly

A note on Web Charts🕸️ (aka: Radar Chart, Spider Chart):

Pros✅

  • Displays outliers evidently (Loki’s Deception)
  • Depict clear comparison across the same radial feature (comparison of strength across Iron-man, Thor & Loki )

Cons❌

  • It is hard to compare lengths of different spokes, because radial distances are hard to judge visually (comparing whether Loki’s speed is higher or magic)
  • The graph would appear cluttered if too many features are plotted

Where are they primarily used:

  • Comparison of skill levels across players, employees and super heroes XD

Code:

import pandas as pd
import plotly.graph_objects as go
from plotly.subplots import make_subplots
import plotly.express as px
import plotly.io as pio
pio.templates.default = "plotly_white"


df = pd.DataFrame({'Character':["Iron Man","Iron Man","Iron Man","Iron Man","Iron Man","Iron Man","Thor","Thor","Thor","Thor","Thor","Thor","Loki","Loki","Loki","Loki","Loki","Loki"], 
                   'Skill':["Deception","Strength","Magic","Intelligence","Leadership","Speed","Deception","Strength","Magic","Intelligence","Leadership","Speed","Deception","Strength","Magic","Intelligence","Leadership","Speed"],
                   'Score':[60,70,0,90,90,70,30,95,80,50,80,70,100,30,80,95,35,75]})
 
df.head()
Table Output
fig = px.line_polar(df, r='Score', theta='Skill', line_close=True,color='Character')
fig.update_traces(fill='toself')
fig.update_layout(
    title={
        'text': "Dummy skill scores across Marvel Characters",
        'x':0.5,
        'xanchor': 'center',
        'yanchor': 'top'})
fig.update_layout(legend=dict(
    orientation="h",
    yanchor="bottom",
    y=-.15,
    xanchor="right",
    x=0.6
))

fig.show()
Chart Output

Three Pie-Chart subplots using Python Plotly

Creating data to create three plotly pie charts side-by-side

import pandas as pd
import plotly.graph_objects as go
from plotly.subplots import make_subplots
df = pd.DataFrame({'Country':["Japan","Japan","Japan","Japan","Japan","Japan","Japan","China","China","China","China","China","China","China","China","China","China","Russia","Russia","Russia","Russia","Russia","Russia","Russia","Russia","Russia","Russia","Russia"], 
                   'Company':["Toyota","Volkswagen","BMW","Ford","Honda","Hyundai","Nissan","Toyota","Volkswagen","BMW","Ford","Honda","Hyundai","Nissan","Ferrari","Tesla","Mahindra","Toyota","Volkswagen","BMW","Ford","Honda","Hyundai","Nissan","Tata","Mahindra","Ferrari","Tesla"],
                   'Sales Percentage':[0.052149,12.715408,0.546859,7.103997,0.016913,58.241407,21.323267,0.002829,0.079224,0.813744,0.726598,0.002264,40.528764,0.435166,0.175991,15.204794,42.030626,0.013739,0.220067,0.011241,0.435887,0.931225,0.005246,24.988447,0.92448,0.256536,11.839394,60.373739,]})
 
df.head()
fig = make_subplots(rows=1, cols=3,specs=[[{"type": "pie"}, {"type": "pie"},{"type": "pie"} ]])

df_japan=df[df["Country"]=="Japan"]
fig.add_trace(go.Pie(labels=df_japan['Company'], values=df_japan['Sales Percentage'], hole=.5),1,1)

df_china=df[df["Country"]=="China"]
fig.add_trace(go.Pie(labels=df_china['Company'], values=df_china['Sales Percentage'], hole=.5),1,2)

df_russia=df[df["Country"]=="Russia"]
fig.add_trace(go.Pie(labels=df_russia['Company'], values=df_russia['Sales Percentage'], hole=.5),1,3)
fig.update_layout(
    title={'text': "Dummy Car Sales Percentages Across Countries",'x':0.5,'xanchor': 'center','yanchor': 'top'},
    annotations=[dict(text='Japan', x=0.12, y=0.5, font_size=20, showarrow=False),
                 dict(text='China', x=0.5, y=0.5, font_size=20, showarrow=False),
                 dict(text='Russia', x=0.89, y=0.5, font_size=20, showarrow=False)]
    )

fig.show()

Blog at WordPress.com.

Up ↑