matplotlibでレーダーチャートを描画
matplotlibでレーダーチャートを描画したいのですが、うまくいきません。
以下を実行すると、新たに2次元のプロット図が作成されてしまい、レーダーチャートに反映されません。
plt.xticks(angles[:-1], categories, color='grey', size=12)
ax.set_rlabel_position(180)
plt.yticks([1,2,3,4,5], ["1","2","3","4", "5"], color="grey", size=7)
plt.ylim(0,5)
スクリプト全文は以下です。
import pandas as pd
import matplotlib.pyplot as plt
from math import pi
%matplotlib notebook
list1=[['5.0','4.9','4.8', '3.9', '4.7', '4.9', '4.7'], ['3.5','3.1','3.0','2.0','2.7','3.1','3.0'], ['4.3','4.3','3.9','2.6','3.6','3.9','4.2']]
index1 = ["cluster0", "cluster1", "cluster2"]
columns1 =["class","labo","job","access","facility","friends","life"]
data = pd.DataFrame(data=list1, index=index1, columns=columns1)
categories=list(data)
values_list = data.values.tolist()
cluster0_list = values_list[0]
cluster1_list = values_list[1]
cluster2_list = values_list[2]
cluster0_list += cluster0_list[:1]
cluster1_list += cluster1_list[:1]
cluster2_list += cluster2_list[:1]
cluster0_list
N = len(categories)
angles = [n / float(N) * 2 * pi for n in range(N)]
angles += angles[:1]
ax = plt.subplot(111, polar=True)
plt.xticks(angles[:-1], categories, color='grey', size=12)
ax.set_rlabel_position(180)
plt.yticks([1,2,3,4,5], ["1","2","3","4", "5"], color="grey", size=7)
plt.ylim(0,5)
ax.plot(angles, cluster0_list, linewidth=1,c='m', linestyle='solid')
ax.plot(angles, cluster1_list, linewidth=1,c='m', linestyle='solid')
ax.plot(angles, cluster2_list, linewidth=1,c='m', linestyle='solid')