Home > other >  Wordcloud make word cloud single words is too long (more than 8) times wrong, how should solve?
Wordcloud make word cloud single words is too long (more than 8) times wrong, how should solve?

Time:10-02

TypeError Traceback (the most recent call last)

58 prefer_horizontal=0.9,
59 max_words=1,
- & gt; 60 contour_color='steelblue). Generate_from_frequencies (dict_fre)
61 # img_colors=ImageColorGenerator (image)
62 # font color for the color of the background picture

D: \ ProgramData \ Anaconda3 \ lib \ site - packages \ wordcloud \ wordcloud py in generate_from_frequencies (self, frequencies, max_font_size)
481 while True:
482 # try to find a position
--> The font=483 ImageFont. Truetype (self font_path, font_size)
484 # transpose the font optionally
485 transposed_font=ImageFont. TransposedFont (

D: \ ProgramData \ Anaconda3 \ lib \ site - packages \ PIL \ ImageFont py in truetype (font, size, index, encoding, layout_engine)
638
639 try:
--> 640 return freetype (font)
641 the except IOError:
642 if not isPath (font) :

D: \ ProgramData \ Anaconda3 \ lib \ site - packages \ PIL \ ImageFont py in freetype (font)
635
636 def freetype (font) :
--> 637 return FreeTypeFont (font, size, index, encoding, layout_engine)
638
639 try:

D: \ ProgramData \ Anaconda3 \ lib \ site - packages \ PIL \ ImageFont py in __init__ (self, the font, size, index, encoding, layout_engine)
The return of 184
185 the self. The font=core. Getfont (
--> 186 the font, size, index, encoding, layout_engine=layout_engine
187)
188 else:

TypeError: integer argument expected, got float

CodePudding user response:

Source:
% matplotlib inline
The import matplotlib
The import numpy as np
The from PIL import Image
The import re
The import jieba
The import TQDM
The import time
The from wordcloud import wordcloud, ImageColorGenerator
The import matplotlib. Pyplot as PLT



# http://www.cnblogs.com/hatemath/
# open storage project name TXT file
Dict_fre={}

With the open (' d: \ \ python \ \ ciyun200 TXT ', 'r', encoding="utf-8") as f:
# word=(f.r ead ())
Trainlines=f.r eadlines # () returns each line of data
# print (trainlines)
For the line in trainlines:
# print (line)
The line=line. Replace (' \ n ', ')
The line=line. The split ('/') # according to the division of the blank space key data in each row
dict_value=https://bbs.csdn.net/topics/{(line [0]) : int (eval (line [1])//1000)}
Dict_fre. Update (dict_value)
Dict_fre={' 12345678 ': 35,' 12345678 ', 4}
# print (dict_fre)
F. lose ()
# image=np. Array (image. Open (' 12366. PNG '))
The font=r 'C: \ \ Windows \ \ fonts \ \ msyh the vera.ttf'

# db=cx_Oracle. Connect (' boxidb/logonbszx @ localhost: 1521/boxidb ')
# cur=the cursor ()
# remove English, keep Chinese
# resultword=re. Sub (" [A Za - z0-9 \ [\ ` \ \ ~!, @, #, $\ ^ \ & amp; \ * \ \ (\)=\ | the \ {\} \ ': \ \. \' \ \ [\] \ \ & lt; \ & gt; \ \? \ ~ \ \ @ # \ \ \ \ & amp; \ * \ %] ", "", the word)
# wordlist_after_jieba=jieba. The cut (resultword)
# wl_space_split="". Join (wordlist_after_jieba)
# # to the historical data of participle
# SQL="select kwords, cipin from (select fenci as kwords, count (fenci) as cipin from FENCIJIEGUO t where t.f enci<> '\ t' and t.f enci<> '\ n' and t.f enci<> '\ r' and t.f enci<> "' and fenci<> 'None' and length (fenci) & gt; 2 group by fenci order by count (fenci) DESC) where rownum
=200"# cur. Execute (SQL)
# rows=cur. Fetchall ()
# for the row in rows:
Print (' was generating word cloud... ')
My_wordcloud=WordCloud (scale=1,
# mask=image,
Font_path=the font,
Width=800,
Height=600,
# mode='RGBA',
Background_color='white',
Min_font_size=2,
Max_font_size=200,

font_step=0.5,Random_state=30,
Contour_width=10,

prefer_horizontal=0.9,Max_words=1,
Contour_color='steelblue). Generate_from_frequencies (dict_fre)
# img_colors=ImageColorGenerator (image)
# font color for the color of the background picture
# my_wordcloud. Recolor (color_func=img_colors)
# shows the generated word cloud
PLT. Imshow (my_wordcloud, interpolation='bilinear')
PLT. Axis (" off ")
PLT. The show ()
Print (' cloud generated word! ')
# cur. Close ()
# the db. The close ()
My_wordcloud. To_file (' ciyun. PNG ')
  • Related