用matplotlib畫雷達圖,網上流傳的版本其實都是官網的一個例子。但是那個例子太復雜,而且它封裝了幾個類,讓人難以一眼看出其本質。
我給出一個簡單的解決方法,沒有任何封裝。作本文的原因,是為了回答百度網友的提問。 好吧,圖很丑~~~。
原問題見:http://zhidao.baidu.com/question/1048071753829017339.html?fr=qlquick&entry=qb_browse_word
【效果圖】
增加一個數據,並且使用了填充
【源代碼】
''' matplotlib雷達圖 ''' import numpy as np import matplotlib.pyplot as plt #=======自己設置開始============ #標簽 labels = np.array(['藝術A','調研I','實際R','常規C','企業E','社會S']) #數據個數 dataLenth = 6 #數據 data = np.array([1,4,3,6,4,8]) #========自己設置結束============ angles = np.linspace(0, 2*np.pi, dataLenth, endpoint=False) data = np.concatenate((data, [data[0]])) # 閉合 angles = np.concatenate((angles, [angles[0]])) # 閉合 fig = plt.figure() ax = fig.add_subplot(111, polar=True)# polar參數!! ax.plot(angles, data, 'bo-', linewidth=2)# 畫線
ax.fill(angles, data, facecolor='r', alpha=0.25)# 填充 ax.set_thetagrids(angles * 180/np.pi, labels, fontproperties="SimHei") ax.set_title("matplotlib雷達圖", va='bottom', fontproperties="SimHei")
ax.set_rlim(0,10) ax.grid(True) plt.show()