In [129]:
%matplotlib inline
import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns
import numpy as np
In [130]:
ratings = pd.read_csv('ratings.csv')
ratings.columns = [x.replace('_', ' ') for x in ratings.columns]
ratings['plot_title'] = ratings.apply(lambda x: "{}\nby {}".format(x.Title, x.Author),
axis=1)
ratings = ratings.set_index(['Author', 'Title'], drop=True)
ratings
Out[130]:
In [131]:
labels = [x.replace(' ', '\n') for x in ratings.columns[:-1]]
for i in range(len(ratings)):
stats = ratings.iloc[i, :-1].values
angles = np.linspace(0, 2*np.pi, len(labels), endpoint=False)
stats = np.concatenate((stats,[stats[0]]))
angles = np.concatenate((angles,[angles[0]]))
fig = plt.figure(figsize=(5,5))
ax = fig.add_subplot(111, polar=True)
ax.plot(angles, stats, 'o-', linewidth=2)
ax.fill(angles, stats, alpha=0.25)
ax.set_thetagrids(angles * 180/np.pi, labels)
ax.set_rlabel_position(-90)
ax.set_theta_zero_location(loc="NW", offset=15)
ax.set_rmax(6)
ax.tick_params(pad=10)
ax.set_title(ratings.iloc[i].plot_title, pad=40)
ax.grid(True)
plt.tight_layout()
plt.savefig('{}.png'.format(ratings.iloc[i].plot_title))
plt.show()
In [ ]: