一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

腳本之家,腳本語言編程技術及教程分享平臺!
分類導航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

服務器之家 - 腳本之家 - Python - 用Python分析3天破10億的《我不是藥神》到底神在哪?

用Python分析3天破10億的《我不是藥神》到底神在哪?

2021-03-16 00:41大數據v Python

我不是藥神這部劇真的是很火,三天破10億。接下來腳本之家小編給大家帶來了用Python來看3天破10億的《我不是藥神》到底神在哪?感興趣的朋友跟隨腳本之家小編一起看看吧

導讀:《我不是藥神》是由文牧野執導,徐崢、王傳君、周一圍、譚卓、章宇、楊新鳴等主演的喜劇電影,于 2018 年 7 月 6 日在中國上映。

用Python分析3天破10億的《我不是藥神》到底神在哪?

影片在未上映前,大規模的點映積攢了相當高的人氣和口碑, 截止 7 月 9 日凌晨:豆瓣評分:9.0 分,貓眼:9.7 分,淘票票:9.5 分,時光網:8.8 分 。

為什么我說這三個網站呢,因為我們今天近 5000+ 條短評數據就來自于此,用專業的數據更有說服力。

用Python分析3天破10億的《我不是藥神》到底神在哪?

綜合幾家的數據:五星推薦如此之高,生活環境是真實的,情緒是真實的,困境也是真實的,甚至女主角是一個真實的上了年紀的美女,有真實的皺紋!真實才能帶來沉浸體驗。表面說的是藥,深層說的是命。

藥能治病,命卻不由自主,直面中國底層生命的苦難和尊嚴,也沒有逃避對社會制度和商業法則的拷問,這是影片鍥入中國現實的關鍵,也是引發大眾共鳴的核心。

用Python分析3天破10億的《我不是藥神》到底神在哪?

盛世危言,卻讓人能看到希望,這部影片極有可能成為 2018 年最具有爆炸性的話題。這也許就是未播先火,豆瓣 16 年后首部 9.0 高分電影的原因。

今天我們用 5000+ 條數據來分析一下,哪些地區,什么樣的人,喜歡這部電影。

程勇只是個賣印度神油的小販,日子過的還湊合。老爹血管瘤急著做手術,住院沒錢,妻子要帶兒子移民去國外發展,靠賣印度神油掙來的錢連水電費都交不起,處處都需要錢。

用Python分析3天破10億的《我不是藥神》到底神在哪?

神秘男子呂受益找到程勇,讓他從印度幫忙代購一款藥物。呂受益患有血液癌癥,需要長期服用抗癌藥物進行治療。

用Python分析3天破10億的《我不是藥神》到底神在哪?

正版藥「瑞士格列寧」非常昂貴,普通人家根本供應不起,但在印度有一款仿制藥「印度格列寧」價格卻只有 1/20,但在中國是屬于禁藥,走私被抓,是需要負法律責任的。

在巨大利益的驅使下,思慧,神父,黃毛先后出場,賣藥五人組團建成功,他成為一名“藥販子”。

用Python分析3天破10億的《我不是藥神》到底神在哪?

對于病友來說,他們擁有了活下去的機會,紛紛給程勇送錦旗,自此稱其為“藥神”。

代購的藥出現問題,假藥販子張長林的出現威脅程勇,怕被抓,賣藥組正式散伙。

程勇開了工廠,呂受益死,張長林跑路,讓程勇完成第一次蛻變,許多病人無藥可吃,程勇再次去印度并重新團建賣藥。

用Python分析3天破10億的《我不是藥神》到底神在哪?

警方嚴打假藥販子,張長林被抓。警方發現程勇窩點,黃毛為了掩護程勇而死,讓他完成第二次蛻變。

以賠本價繼續代購印度藥,送兒子移民,晚上賣藥被警察抓。三年后出獄,外面已是改天換地。

《我不是藥神》的現實意義大于電影本身,許多人評論這部電影都有些揚眉吐氣的感覺,大家都在做一個中國電影終于敢說真話的夢。

截止 7 月 9 日凌晨,累積票房超過 13 個億,占當天票房近 84%。

用Python分析3天破10億的《我不是藥神》到底神在哪?

是哪些地區貢獻的票房更多一些,通過數據分析發現:

用Python分析3天破10億的《我不是藥神》到底神在哪?

如這張圖片動態展示的情況,你會發現貢獻最多的還是:北京、上海、廣州,二線城市同樣成為票房的貢獻者。

用Python分析3天破10億的《我不是藥神》到底神在哪?

從畫像來看,更趨于中年,油膩的中年,人人都怕老病死,人人都怕上下為難,人人都有為謀生計不得不做的事情,人人亦都向往真與善……是這些時刻集中起來讓煽情的《藥神》不那么脫離現實。

用Python分析3天破10億的《我不是藥神》到底神在哪?

從數據上來看,好看,現實,好片,感人,淚點,作品很棒。

“領導,我求求你,別再查「假藥」了行么。這藥假不假,我們這些吃的人還不知道么?”

“我吃了三年正版藥,房子吃沒了,家也吃垮了。現在好不容易有了便宜藥,可你們非說這是「假藥」。不吃藥,我們就只能等死。”

用Python分析3天破10億的《我不是藥神》到底神在哪?

《我不是藥神》戳中的是每個人的痛點,誰能保證這一輩子自己和家人不生病呢?

一旦遇上大病,動輒上萬的高昂醫藥費讓普通人家根本無力承擔。一人生病,全家拖垮,真不是危言聳聽。

下面我們回歸技術,分享一下我們如何獲取的數據:

首先是豆瓣,豆瓣自從去年 10 月份已經全面禁止爬取數據,僅僅放出 500 條數據,豆瓣封 ip,白天一分鐘可以訪問 40 次,晚上一分鐘可以訪問 60 次,超過限制次數就會封 ip。

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import urllib
import requests
from urllibimport request
import time
header = {'user-agent': 'mozilla/5.0 (windows nt 10.0; win32; x32; rv:54.0) gecko/20100101 firefox/54.0',
'connection': 'keep-alive'}
cookies = 'v=3; iuuid=1a6e888b4a4b29b16fba1299108dbe9cdcb327a9713c232b36e4db4ff222cf03; webp=true; ci=1%2c%e5%8c%97%e4%ba%ac; __guid=26581345.3954606544145667000.1530879049181.8303; _lxsdk_cuid=1646f808301c8-0a4e19f5421593-5d4e211f-100200-1646f808302c8; _lxsdk=1a6e888b4a4b29b16fba1299108dbe9cdcb327a9713c232b36e4db4ff222cf03; monitor_count=1; _lxsdk_s=16472ee89ec-de2-f91-ed0%7c%7c5; __mta=189118996.1530879050545.1530936763555.1530937843742.18'
def html_prase(url):
r = requests.get(url).content
return r
cookie = {}
for line in cookies.split(';'):
name, value = cookies.strip().split('=', 1)
 cookie[name] = value
def html_prase(url):
r = requests.get(url).content
return r
for iin range(1, 100):
print('正在打印第%s頁' % i)
try:
url= 'http://m.maoyan.com/mmdb/comments/movie/1200486.json?_v_=yes&offset=%s&' % (
i* 15)
print(url)
 proxy = html_prase('http://172.17.0.29:5010/get/')..decode('utf-8') # 代理是自建代理池,有需要使用代理的可以聯系我,知乎id:布道
html = requests.get(url=url, cookies=cookie, headers=header,
proxies={"http": "http://{}".format(proxy)}).content
 data = json.loads(html.decode('utf-8'))['cmts']
for item in data:
comment = item['content']
  date = item['time'].split(' ')[0]
  rate = item['score']
  city = item['cityname']
img= item['avatarurl']
print(date, rate, comment, city, )
with open('maoyan_08.txt', 'a', encoding='utf-8') as f:
f.write(date + ',' + str(rate) + ',' + comment + ',' + comment + ',' + city + '\n')
if img:
f = open('c:\\users\my\desktop\yaoshen\img\\' + img.split('/')[-1], 'wb')
f.write((urllib.request.urlopen(img)).read())
except:
continue
time.sleep(5 + float(random.randint(1, 100)) / 20)

另外一種方式:

(anyproxy+js+python+monkeyrunner),可以爬取 web 靜態網站、app 應用、js 渲染數據的動態網站的數據都可以進行爬取。

用Python分析3天破10億的《我不是藥神》到底神在哪?

 

安裝使用,請查閱官方 github:

https://github.com/alibaba/anyproxy

js 代碼:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
var logmap = {}
var fs = require('fs');
var iconv = require('iconv-lite');
var logger = fs.createwritestream('./urllog.log', {
 flags: 'a' // 'a' means appending (old data will be preserved)
})
function logpagefile(url) {
 if (!logmap[url]) {
 logmap[url] = true;
 logger.write(url + '\r\n');
 }
}
function postdata(post_data, path, cb) {
 // // build the post string from an object
 // var post_data = json.stringify({
 // 'data': data
 // });
 // an object of options to indicate where to post to
 var post_options = {
 host: '127.0.0.1',
 port: '9999',
 path: '/' + path,
 method: 'post',
 headers: {
  'content-type': 'application/json',
  'content-length': buffer.bytelength(post_data)
 }
 };
 var http = require('http');
 // set up the request
 var post_req = http.request(post_options, function (res) {
 res.setencoding('utf8');
 res.on('data', cb);
 });
 logger.write('request post data 1\r\n')
 // post the data
 post_req.write(post_data);
 logger.write('request post data 2\r\n')
 post_req.end();
}
module.exports = {
 summary: 'a rule to modify response',
 * beforesendresponse(requestdetail, responsedetail) {
 if (/movie\/1200486/i.test(requestdetail.url)) {
  logger.write('matched: ' + requestdetail.url + '\r\n');
  if (responsedetail.response.tostring() !== "") {
  logger.write(responsedetail.response.body.tostring());
  var post_data = json.stringify({
   'url': requestdetail.url,
   'body': responsedetail.response.body.tostring()
  });
  logger.write("post comment to server -- ext");
  postdata(post_data, 'douban_comment', function (chunk) {
  });
  }
 }
 },
};

使用 anyproxy 加載 js 代碼:anyproxy -i --rule wxrule.js

service 代碼部分:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/usr/bin/env python3
import asyncio
import re
import textwrap
import threading
import time
import os
import pymysql
from mysqlmgrimport mysqlmgr
from mongomgrimport mongomanager
from subprocess import call
import requests
from lxmlimport etree
from lxmlimport html
from aiohttp.webimport application, response, streamresponse, run_app
import json
state_running = 1
state_in_transaction = 2
running_state= 0
run_swipe= true
last_history_time= time.clock()
# a thread to save data to database in background
def insert_to_database(biz, msglist):
try:
for msg in msglist:
print(biz)
print(msg['comm_msg_info']['id'])
mongo_mgr.enqueue_data(msg['comm_msg_info']['id'], biz, msg )
except exception as e:
print(e)
def save_data(biz, msglist_str):
save_thread= threading.thread(target=insert_to_database, args=(biz, msglist_str,))
save_thread.setdaemon(true)
save_thread.start()
def swipe_for_next_page():
while run_swipe:
time.sleep(5)
if time.clock() - last_history_time>120:
if running_state== state_running:
reenter()
continue
call(["adb", "shell", "input", "swipe", "400", "1000", "400", "200"])
def reenter():
global running_state
running_state= state_in_transaction
# 模擬側滑實現返回上一頁
call(["adb", "shell", "input", "swipe", "0", "400", "400", "400"])
time.sleep(2)
# 點擊"進入歷史消息",每個手機的位置不一樣,需要單獨設置 x 和 y
call(["adb", "shell", "input", "tap", "200", "1200"])
time.sleep(2)
header={'user-agent':'mozilla/5.0 (windows nt 10.0; win64; x64; rv:54.0) gecko/20100101 firefox/54.0','connection':'keep-alive'}
def html_prase(url):
r = requests.get(url,header).content
return html.fromstring(r)
async def report_url(request):
resp = streamresponse()
 data = await request.json()
url= data['url']
# print("url reported: " + url)
biz = re.findall('__biz=(.*?)\&', url)
if len(biz) == 0:
await resp.prepare(request)
return resp
 biz = biz[0]
print('----------------\r\n'+ biz + '\r\n----------------\r\n')
mysql_mgr.enqueue_biz(biz, '')
bizs.add(biz)
 biz = biz.encode('utf8')
resp.content_type= 'text/plain'
await resp.prepare(request)
resp.write(biz)
await resp.write_eof()
return resp
async def intro(request):
txt = textwrap.dedent("""\
 type {url}/hello/john {url}/simple or {url}/change_body
 in browser url bar
 """).format(url='127.0.0.1:8080')
 binary = txt.encode('utf8')
 resp = streamresponse()
resp.content_length= len(binary)
resp.content_type= 'text/plain'
await resp.prepare(request)
resp.write(binary)
return resp
async def simple(request):
return response(text="simple answer")
async def change_body(request):
resp = response()
resp.body= b"body changed"
resp.content_type= 'text/plain'
return resp
# coding=utf-8
async def app_douban_comment(request):
resp = streamresponse()
 data = await request.json()
global running_state
global last_history_time
msg_data= json.loads(data['body'])['data']['cts']
for item in msg_data:
comment = item['ce'].strip().replace('\n','')
 rate = item['cr']
print(comment, rate)
with open('date_rate_comment_sg.txt', 'a', encoding='utf-8') as f:
f.write('2018-07-06' + ',' + str(rate) + ',' + comment + '\n')
last_history_time= time.clock()
resp.content_type= 'text/plain'
await resp.prepare(request)
await resp.write_eof()
return resp
last_history_time= time.clock()
resp.content_type= 'text/plain'
await resp.prepare(request)
await resp.write_eof()
return resp
async def init(loop):
app = application()
app.router.add_get('/', intro)
app.router.add_post('/url', report_url)
app.router.add_post('/douban_comment', app_douban_comment)
return app
def start_swipe_thread():
try:
t = threading.thread(
target=swipe_for_next_page, name='swipe')
# set daemon so main thread can exit when receives ctrl-c
t.setdaemon(true)
t.start()
except exception:
print("error: unable to start thread")
loop = asyncio.get_event_loop()
app = loop.run_until_complete(init(loop))
run_app(app, host='127.0.0.1', port=9999)

這是示例代碼,實際使用過程,需要進行微調。獲取貓眼數據,最難是難在找貓眼 app 的數據接口。

 

我費了很大力氣才找到:

http://m.maoyan.com/mmdb/comments/movie/1200486.json?_v_=yes&offset=15'

 

接口怎么使用,直接看代碼,獲取淘票票的數據需要你自己去嘗試找一下。

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import json
import random
import urllib
import requests
from urllibimport request
import time
header = {'user-agent': 'mozilla/5.0 (windows nt 10.0; win32; x32; rv:54.0) gecko/20100101 firefox/54.0',
'connection': 'keep-alive'}
cookies ='v=3; iuuid=1a6e888b4a4b29b16fba1299108dbe9cdcb327a9713c232b36e4db4ff222cf03; webp=true; ci=1%2c%e5%8c%97%e4%ba%ac; __guid=26581345.3954606544145667000.1530879049181.8303; _lxsdk_cuid=1646f808301c8-0a4e19f5421593-5d4e211f-100200-1646f808302c8; _lxsdk=1a6e888b4a4b29b16fba1299108dbe9cdcb327a9713c232b36e4db4ff222cf03; monitor_count=1; _lxsdk_s=16472ee89ec-de2-f91-ed0%7c%7c5; __mta=189118996.1530879050545.1530936763555.1530937843742.18'
cookie = {}
for line in cookies.split(';'):
name, value = cookies.strip().split('=', 1)
 cookie[name] = value
def html_prase(url):
r = requests.get(url).content
return r
for iin range(1, 100):
print('正在打印第%s頁' % i)
try:
url= 'http://m.maoyan.com/mmdb/comments/movie/1200486.json?_v_=yes&offset=%s&' %(i*15) +'starttime=2018-07-01%2012%3a30%3a42'
print(url)
 html = requests.get(url=url, cookies=cookie, headers=header).content
 data = json.loads(html.decode('utf-8'))['cmts']
for item in data:
comment = item['content']
  date = item['time'].split(' ')[0]
  rate = item['score']
  city = item['cityname']
img= item['avatarurl']
print(date, rate, comment, city, )
with open('maoyan_08.txt', 'a', encoding='utf-8') as f:
f.write(date + ',' + str(rate) + ',' + comment +',' + comment + ','+ city +'\n')
if img:
f = open('c:\\users\my\desktop\yaoshen\img\\' + img.split('/')[-1], 'wb')
f.write((urllib.request.urlopen(img)).read())
except:
break
time.sleep(5 + float(random.randint(1, 100)) / 20)

動態地圖展示代碼:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from pyechartsimport style
from pyechartsimport geo
city =[]
with open('maoyan.txt', mode='r', encoding='utf-8') as f:
rows = f.readlines()
for row in rows:
if len(row.split(',')) == 5:
city.append(row.split(',')[4].replace('\n',''))
def all_list(arr):
result = {}
for iin set(arr):
result[i] = arr.count(i)
return result
data = []
for item in all_list(city):
data.append((item,all_list(city)[item]))
style = style(
title_color="#fff",
title_pos="center",
width=1200,
height=600,
background_color='#404a59'
)
geo = geo( "《我不是藥神》評論人群地理位置","數據來源:知乎id:布道", **style.init_style)
attr, value = geo.cast(data)
geo.add("", attr, value, visual_range=[0, 100],
visual_text_color="#fff", is_legend_show=false,
symbol_size=20, is_visualmap=true,
tooltip_formatter='{b}',
label_emphasis_textsize=15,
label_emphasis_pos='right')
geo.render()

每天爬取數據量代碼:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from pyechartsimport effectscatter
from pyechartsimport style
style= style(
title_color="#191970",
title_pos="left",
width=900,
height=450,
background_color='#f8f8ff'
)
es = effectscatter("《我不是藥神》短評數據情況","數據來源:知乎id:布道", **style.init_style)
es.add("", [1], [270], symbol_size=20, effect_scale=4,
effect_period=5, symbol="pin")
es.add("", [2], [606], symbol_size=20, effect_scale=4,
effect_period=5, symbol="pin")
es.add("", [3], [542], symbol_size=20, effect_scale=4,
effect_period=5, symbol="pin")
es.add("", [4], [550], symbol_size=20, effect_scale=4,
effect_period=5, symbol="pin")
es.add("", [5], [656], ssymbol_size=20, effect_scale=4,
effect_period=5, symbol="pin")
es.add("", [6], [850], ssymbol_size=20, effect_scale=4,
effect_period=5, symbol="pin")
es.add("", [7], [993], symbol_size=20, effect_scale=4,
effect_period=5, symbol="pin")
es.add("", [8], [903], symbol_size=20, effect_scale=4,
effect_period=5, symbol="pin")
es.render()

五星推薦河流圖代碼:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
from pyechartsimport style
from pyechartsimport themeriver
 
data = [
 ['2018/07/08', 802, '五星'], ['2018/07/08', 28, '四星'], ['2018/07/08', 9, '三星'], ['2018/07/08',8, '二星'],
 ['2018/07/08', 4, '一星'],
 
 ['2018/07/07',802, '五星'], ['2018/07/07',166, '四星'], ['2018/07/07',17, '三星'],['2018/07/07',0, '二星'],['2018/07/07',8, '一星'],
 ['2018/07/06', 667, '五星'], ['2018/07/06', 156, '四星'], ['2018/07/06', 13, '三星'], ['2018/07/06', 10, '二星'],['2018/07/06', 4, '一星'],
 ['2018/07/05', 567, '五星'], ['2018/07/05', 76, '四星'], ['2018/07/05', 13, '三星'], ['2018/07/05', 0, '二星'],['2018/07/05', 0, '一星'],
 ['2018/07/04', 467, '五星'], ['2018/07/04', 67, '四星'], ['2018/07/04', 16, '三星'], ['2018/07/04', 0, '二星'],['2018/07/04', 0, '一星'],
 ['2018/07/03', 478, '五星'], ['2018/07/03', 56, '四星'], ['2018/07/03', 8, '三星'], ['2018/07/03', 0, '二星'],['2018/07/03', 0, '一星'],
 ['2018/07/02', 531, '五星'], ['2018/07/02', 67, '四星'], ['2018/07/02', 8, '三星'], ['2018/07/02', 0, '二星'],['2018/07/02', 0, '一星'],
 ['2018/07/01', 213, '五星'], ['2018/07/01', 45, '四星'], ['2018/07/01', 5, '三星'], ['2018/07/01', 1, '二星'],
 ['2018/07/01', 1, '一星'],
]
style = style(
title_color="#191970",
title_pos="left",
width=1200,
height=600,
background_color='#f8f8ff'
)
tr = themeriver("《我不是藥神》星級推薦","數據來源:知乎id:布道", **style.init_style)
tr.add(['五星', '四星', '三星', '二星', '一星',], data, is_label_show=true)
tr.render()

詞云圖:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import pickle
from osimport path
import jieba
import matplotlib.pyplotas plt
from wordcloudimport wordcloud, stopwords, imagecolorgenerator
def make_worldcloud(file_path):
text_from_file_with_apath= open(file_path,'r',encoding='utf-8').read()
wordlist_after_jieba= jieba.cut(text_from_file_with_apath, cut_all=false)
wl_space_split= " ".join(wordlist_after_jieba)
print(wl_space_split)
backgroud_image= plt.imread('./1.jpg')
print('加載圖片成功!')
'''設置詞云樣式'''
stopwords= stopwords.copy()
stopwords.add("哈哈")
stopwords.add("電影")
stopwords.add("真的")
stopwords.add("就是")
stopwords.add("真是")
stopwords.add("中國")
stopwords.add("沒有")
stopwords.add("可以")
stopwords.add("一部")
stopwords.add("還是")
stopwords.add("最后")
stopwords.add("一個") #可以加多個屏蔽詞#可以加多個屏蔽詞
wc= wordcloud(
width=1024,
height=768,
background_color='white',# 設置背景顏色
mask=backgroud_image,# 設置背景圖片
font_path='e:\simsun.ttf', # 設置中文字體,若是有中文的話,這句代碼必須添加,不然會出現方框,不出現漢字
max_words=600, # 設置最大現實的字數
stopwords=stopwords,# 設置停用詞
max_font_size=400,# 設置字體最大值
random_state=50,# 設置有多少種隨機生成狀態,即有多少種配色方案
)
wc.generate_from_text(wl_space_split)#開始加載文本
img_colors= imagecolorgenerator(backgroud_image)
wc.recolor(color_func=img_colors)#字體顏色為背景圖片的顏色
plt.imshow(wc)# 顯示詞云圖
plt.axis('off')# 是否顯示x軸、y軸下標
plt.show()#顯示
 # 獲得模塊所在的路徑的
d = path.dirname(__file__)
# os.path.join(): 將多個路徑組合后返回
wc.to_file(path.join(d, "h11.jpg"))
print('生成詞云成功!')
make_worldcloud('cloud.txt')

圖像畫像代碼:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import os
from math import sqrt
from pil import image
#path是存放好友頭像圖的文件夾的路徑
path = 'c:\\users\my\desktop\yaoshen\img\\'
pathlist= []
for item in os.listdir(path):
imgpath= os.path.join(path,item)
pathlist.append(imgpath)
total = len(pathlist)#total是好友頭像圖片總數
line = int(sqrt(total))#line是拼接圖片的行數(即每一行包含的圖片數量)
newimage= image.new('rgb', (128*line,128*line))
x = y = 0
for item in pathlist:
try:
img= image.open(item)
img= img.resize((128,128),image.antialias)
newimage.paste(img, (x * 128 , y * 128))
 x += 1
except ioerror:
print("第%d行,%d列文件讀取失敗!ioerror:%s" % (y,x,item))
 x -= 1
if x == line:
x = 0
y += 1
if (x+line*y) == line*line:
break
newimage.save(path+"final.jpg")

好了,就給大家介紹到這里,希望對大家有所幫助。!

原文鏈接:https://blog.csdn.net/zw0pi8g5c1x/article/details/80997709

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 精品在线播放视频 | 黑人日白人 | 免费午夜影片在线观看影院 | 青青91| 国内精品在线播放 | 红楼梦黄色小说 | 亚洲午夜性春猛交xxxx | 国产一区二区三区免费在线视频 | 我半夜摸妺妺的奶C了她 | 日韩精品免费一级视频 | 日本成熟bbxxxxxxxx | 精品9e精品视频在线观看 | 免费网站直接进入 | 免费观看在线永久免费xx视频 | jk制服喷水| 网站视频免费 | 欧美日韩国产成人综合在线影院 | free性欧洲 | 欧美黑人成人免费全部 | 翁公与小莹在客厅激情 | 久久久久999 | 日本精工厂网址 | 美女操批 | 日本三级大学生17 | 丝瓜茄子绿巨人秋葵榴莲污 | 亚洲国产香蕉视频欧美 | 特黄特黄一级片 | 亚洲冬月枫中文字幕在线看 | www.av免费| 乌克兰肥熟 | 色天天综合网色鬼综合 | 沉香如屑西瓜视频免费观看完整版 | 免费人成在线观看视频播放 | 韩国丽卡三级作品 | 国产精品久久久久久久福利院 | 四虎精品成人a在线观看 | bedfriend泰剧全集免费观看 | 好吊色永久免费视频大全 | 亚洲精品乱码久久久久久蜜桃欧美 | 亚洲国产成人久久精品影视 | 女人把扒开给男人爽 |