笔记:python中的蜘蛛图
生活随笔
收集整理的這篇文章主要介紹了
笔记:python中的蜘蛛图
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
from matplotlib.font_manager import FontProperties
# 數據準備
labels=np.array([u" 推進 ","KDA",u" 生存 ",u" 團戰 ",u" 發育 ",u" 輸出 "])
stats=[83, 61, 95, 67, 76, 88]
# 畫圖數據準備,角度、狀態值
angles=np.linspace(0, 2*np.pi, len(labels), endpoint=False)
stats=np.concatenate((stats,[stats[0]]))
angles=np.concatenate((angles,[angles[0]]))
# 用 Matplotlib 畫蜘蛛圖
fig = plt.figure()
ax = fig.add_subplot(111, polar=True)
ax.plot(angles, stats, 'o-', linewidth=2)
ax.fill(angles, stats, alpha=0.25)
# 設置中文字體
font = FontProperties(fname=r"C:\Windows\Fonts\simhei.ttf", size=14)
ax.set_thetagrids(angles* 180/np.pi, labels, FontProperties=font)
plt.show()
代碼中 flt.figure 是創建一個空白的 figure 對象,這樣做的目的相當于畫畫前先準備一個
空白的畫板。然后 add_subplot(111) 可以把畫板劃分成 1 行 1 列。再用 ax.plot 和
ax.fill 進行連線以及給圖形上色。最后我們在相應的位置上顯示出屬性名。這里需要用到
中文,Matplotlib 對中文的顯示不是很友好,因此我設置了中文的字體 font,這個需要在
調用前進行定義
總結
以上是生活随笔為你收集整理的笔记:python中的蜘蛛图的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 法院触摸屏查询软件
- 下一篇: DB2的数据库备份与恢复