I find a radar plot a helpful tool for visual comparison between items when there are multiple axes. It helps me sort out my thoughts. Therefore I created a small script that helps me turn CSV to a radar plot. See the gist below, and read more about the usage of radar plots here.
So how does it works? you provide a csv file where the columns are the different properties and each record (i.e line) is a different item you want to create a scatter for.
The following figure was obtained based on this csv –
https://gist.github.com/tomron/e5069b63411319cdf5955f530209524a#file-examples-csv
The data in the file is based on – https://www.kaggle.com/datasets/shivamb/company-acquisitions-7-top-companies
And I used the following command –
python csv_to_radar.py examples.csv --fill toself --show_legend --title "Merger and Acquisitions by Tech Companies" --output_file merger.jpeg

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import plotly.graph_objects as go | |
| import plotly.offline as pyo | |
| import pandas as pd | |
| import argparse | |
| import sys | |
| def parse_arguments(args): | |
| parser = argparse.ArgumentParser(description='Parse CSV to radar plot') | |
| parser.add_argument('input_file', type=argparse.FileType('r'), | |
| help='Data File') | |
| parser.add_argument( | |
| '–fill', default=None, choices=['toself', 'tonext', None]) | |
| parser.add_argument('–title', default=None) | |
| parser.add_argument('–output_file', default=None) | |
| parser.add_argument('–show_legend', action='store_true') | |
| parser.add_argument('–show_radialaxis', action='store_true') | |
| return parser.parse_args(args) | |
| def main(args): | |
| opt = parse_arguments(args) | |
| df = pd.read_csv(opt.input_file, index_col=0) | |
| categories = df.columns | |
| data = [go.Scatterpolar( | |
| r=[*row.values, row.values[0]], | |
| theta=categories, | |
| fill=opt.fill, | |
| name=label) for label, row in df.iterrows()] | |
| fig = go.Figure( | |
| data=data, | |
| layout=go.Layout( | |
| title=go.layout.Title(text=opt.title, xanchor='center', x=0.5), | |
| polar={'radialaxis': {'visible': opt.show_radialaxis}}, | |
| showlegend=opt.show_legend | |
| ) | |
| ) | |
| if opt.output_file: | |
| fig.write_image(opt.output_file) | |
| else: | |
| pyo.plot(fig) | |
| if __name__ == "__main__": | |
| main(sys.argv[1:]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Parent Company | 2017 | 2018 | 2019 | 2020 | 2021 | |
|---|---|---|---|---|---|---|
| 3.0 | 5.0 | 7.0 | 7.0 | 4.0 | ||
| 0.0 | 1.0 | 3.0 | 3.0 | 4.0 | ||
| Amazon | 12.0 | 4.0 | 9.0 | 2.0 | 5.0 | |
| 11.0 | 10.0 | 8.0 | 8.0 | 4.0 | ||
| Microsoft | 9.0 | 17.0 | 9.0 | 8.0 | 11.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| numpy==1.22.4 | |
| pandas==1.4.2 | |
| plotly==5.8.0 | |
| python-dateutil==2.8.2 | |
| pytz==2022.1 | |
| six==1.16.0 | |
| tenacity==8.0.1 |
This script looks cool. Any idea why the below modified example when used as the input outputs a plot where the first column data (2017) is absent?
Company,2017,2018,2019,2020,2021,2022,2023,2024,2025,2026
Facebook,3,5,7,7,4,4,34,12,0,0
Twitter,0,1,3,3,4,5,567,0,1,0
Amazon,12,4,9,2,5,19,12,12,1,0
Google,11,10,8,8,4,123,12,123,23,10
Microsoft,9,17,9,8,11,12,11,1,1,0
Thanks, I’m not sure why I initially set `categories = [*df.columns[1:], df.columns[1]]` but if you set `categories = df.column` I think it should work correctly
Thanks Tom for your prompt response. Setting ‘categories=df.columns’ seems to fix the issue