These days I’m playing a simple but interesting Pokemon with stats dataset. Unexpectedlly,the seaborn
and matplotlib
do not support the radar chart. And the matplotlib radar chart sample is totally a mass (186 lines, what the hell). After an afternoon’s work I implemented the radar chart in a much simple way (only 20 lines). Hope this blog could help someone who is try to draw the radar chart in Python.
(Or time to change to R? ;P)
Radar Graph
Initialize
Load libraries and pokemon dataset. Set the label of axis. (‘HP’, ‘Attack’, ‘Defense’, ‘Sp. Atk’, ‘Sp. Def’, ‘Speed’). Here we use the No.386 pokemon as an example to illustrate the chart.
1 | %matplotlib inline |
Polar Settings
Set the angle of polar axis. Here we need to use the np.concatenate
to draw a closed plot in radar chart
1 | angles=np.linspace(0, 2*np.pi, len(labels), endpoint=False). # Set the angle |
Draw the chart
Here we should use the fig.add_subplot
rather than the sns.plt.subplots()
.(notice the “s”). Because the subplots
doesn’t contain the argument “polar”. We can only set the polar axis by subplot
.
Then draw the plot as the frame and fill in the surrounded area by fill()
. At the end set the label of axis and the title then everything done.
1 | fig=sns.plt.figure() |
Here is the stats radar chart: