簡書50W用戶誰才是大牛?——Matplotlib

上個月在簡書上爬取了50多萬的用戶信息存入MongoDB,現(xiàn)在將這些數(shù)據(jù)調(diào)出來做些簡單的分析,主要是練習(xí)Matplotlib,感興趣的可以看看你有沒有上榜,有沒有拖后腿。

詳細爬取策略及代碼傳送門 ??請點這里

all_u_cnt = coll.find().count()
active_u_cnt = coll.find({"follow": {"$ne": 0},
                          "words_count": {"$ne": 0},
                          "get_likes": {"$ne": 0}}).count()

zombie_u_cnt = coll.find({"follow": 0,
                          "words_count": 0,
                          "get_likes": 0}).count()

ordinary_u_cnt = coll.find({"$or":
                          [{"follow": 0},
                           {"words_count": 0},
                           {"get_likes": 0}]}).count() - zombie_u_cnt

if all_u_cnt == active_u_cnt + zombie_u_cnt + ordinary_u_cnt:
    print("抽樣總量:{}\n活躍用戶:{}\n僵尸用戶:{}\n普通用戶:{}".format(all_u_cnt, active_u_cnt, zombie_u_cnt, ordinary_u_cnt))

抽樣總量:533818
活躍用戶:167134
僵尸用戶:102818
普通用戶:263866


plt.figure("pie", figsize=(7, 7))
plt.title('用戶活躍分類', fontsize=24)  
label_tags = ("active", "zombie", "ordinary")
label_values = active_u_cnt, zombie_u_cnt, ordinary_u_cnt,
explode = 0.08, 0, 0
colors = '#FFA500','#C0C0C0','#40E0D0'

patches,l_text,p_text = plt.pie(
        label_values, labels=label_tags, explode=explode,colors=colors,
        autopct='%3.1f % %', labeldistance=1.1, startangle = 60,pctdistance = 0.5, shadow=False,
        )
#labeldistance,文本的位置離遠點有多遠,1.1指1.1倍半徑的位置
#autopct,圓里面的文本格式,%3.1f%%表示小數(shù)有1位,整數(shù)有一位的浮點數(shù)
#shadow,餅是否有陰影
#startangle,起始角度,0,表示從0開始逆時針轉(zhuǎn),為第一塊。一般選擇從90度開始比較好看
#pctdistance,百分比的text離圓心的距離
#patches, l_texts, p_texts,為了得到餅圖的返回值,p_texts餅圖內(nèi)部文本的,l_texts餅圖外label的文本
#改變文本的大小
#方法是把每一個text遍歷。調(diào)用set_size方法設(shè)置它的屬性
for p in patches:
    p.set_alpha(.85)
for t in l_text:
    t.set_size(20)
for t in p_text:
    t.set_size(20)

plt.axis('equal')
plt.legend()
plt.show()

另外通過在50W數(shù)據(jù)中除去僵尸用戶,在剩余的40W多用戶中統(tǒng)計發(fā)現(xiàn),
其中只有9個簽約用戶(這個應(yīng)該不太準(zhǔn),比較遺憾)

平均文章數(shù) : 7.9
平均字?jǐn)?shù) : 9280.67
平均獲贊 : 49.67
平均關(guān)注 : 13.08
平均被粉 : 22.03

散點圖是上面餅圖中31.3%活躍用戶的統(tǒng)計(約15W個散點),活躍用戶即字?jǐn)?shù)、獲贊數(shù)、關(guān)注都不為0的用戶的文章數(shù)及字?jǐn)?shù)分布統(tǒng)計,不難看出風(fēng)水嶺在100篇文章和20w字之內(nèi),如再細分只需調(diào)整刻度即可


user_obj = coll.find({"follow": {"$ne": 0},
                      "words_count": {"$ne": 0},
                      "get_likes": {"$ne": 0}})
art_list = [], wrd_list = []

for _ in user_obj:  
    art_list.append( _['article'])
    wrd_list.append( _['words_count'])

plt.figure(figsize=(12, 8))

plt.subplot(212) 
plt.title('文章數(shù)及字?jǐn)?shù)分布', fontsize=18)
plt.xlabel('文章數(shù)')
plt.ylabel('字?jǐn)?shù)')

plt.scatter(art_list,wrd_list ,s=15 ,c='r',marker='.' ,alpha = 0.2, label='red_point')
# scatter用于繪制散點
plt.xlim(0,500)
plt.ylim(0,1000000)

plt.xticks(range(0,500,50))
plt.yticks(range(0,1000000,200000))
# 不顯示坐標(biāo)軸的值
# plt.xticks(())
# plt.yticks(())
plt.legend()
plt.show()

下面列出各個維度的排行榜


def get_plot():
    index = np.arange(len(user_list))  
    bar_width = 0.6
    opacity = 1
    color_list = ['#C0C0C0']*10
    color_list[0] = '#FF4500'
    color_list[1] = '#FF7F50'
    color_list[2] = '#FFA07A'

    plt.xticks(index, user_list, fontsize=14,rotation= 45, horizontalalignment='right')
    plt.yticks(fontsize=14)
    plt.bar(index , cnt_list, bar_width, alpha=1, color=color_list)

    for m, n in zip(index,cnt_list):
        plt.text(x=m,y= n * 1.02,s=n ,ha='center',va='bottom', fontsize=14)

    plt.show()

##########################################

user_list = []
cnt_list = []
top10_list = coll.find().sort([("fans", -1)]).limit(10)
for i in top10_list:
    user_list.append(i["user_name"])
    cnt_list.append(i["fans"])

plt.figure("Fans Top10", figsize=(12, 8))
plt.title('粉絲數(shù) Top10', fontsize=24)  
plt.xlabel('')  
# plt.ylabel('粉絲數(shù)', fontsize=12, rotation= 90)
plt.ylim(0,120000)
plt.xlim()
width = 0.5

get_plot()
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 簡書產(chǎn)品分析報告 F組:謝少煌 劉冬陽 雷雅茜 秦茜 周莉莉 周俊華 目 錄 一、產(chǎn)品定位 (1)目標(biāo)市場、目標(biāo)用...
    Cherry華女閱讀 2,810評論 3 27
  • 我想說學(xué)習(xí)不是主要的,這學(xué)習(xí)是俠義的,學(xué)習(xí)其實還有廣義,從廣義來說,學(xué)習(xí)無處不在,這個學(xué)習(xí)也是可以被提到那個學(xué)習(xí)的...
    蔡曉秋晴柔媽媽閱讀 419評論 1 2

友情鏈接更多精彩內(nèi)容