python as an introduction, using the generate_from_frequencies method in wordCloud according to the online tutorial, it is found that the key of the incoming dict is segmented again, and there are repeated words. The problem can not be found. Ask for help. The key setting code is as follows
.alice_coloring = np.array(Image.open(path.join(d, "/Users/xxxx/Desktop/alice_color.png")))
alice_mask = np.array(Image.open(path.join(d, "/Users/xxx/Desktop/alice_mask.png")))
-sharp
stopwords = set(STOPWORDS)
stopwords.add("")
-sharp mask
wc = WordCloud(background_color="white", max_words=500, mask=alice_mask,collocations=False,
font_path="/Users/xxxx/Desktop/weibei.ttf", contour_width=3, contour_color="steelblue")
-sharp generate word cloud
wc.generate_from_frequencies(dictM)
-sharp create coloring from image
-sharpimage_colors = ImageColorGenerator(alice_coloring)
wc.to_file(path.join(d, "/Users/xxxx/Desktop/alice.png"))```
dict:
{"Qingdao": 1914, "trestle": 1164, "Badaguan": 1098, "Laoshan": 1030, "May 4th Square": 793, "Flower Stone Building": 597, "Catholic Church": 570, "Little Qingdao": 464,"Lu Xun Park": 433, "firewood splitting Court": 425, "Christian Church": 363, "first Beach": 341, Princess Building: 326, Naval Museum: 314, second Beach: 312, Qingdao Railway Station: 305, Polar Sea World: 279, Zhongshan Park: 247, North Jiushui: 243, signal Mountain Park: 240, Welcome Hotel: 207, Jiaozhou: 204, Home: 191, Stone Old Man Beach: 143, Music Square: 131, "Tsing Tao Beer Museum": 124, "Tsing Tao Beer Factory": 120, "Xiaoyushan Park": 104, "Weihai": 103, "Shangqing Palace": 91, "Tianmu City": 90, "Yunxiao Road Food Street": 88, "Penglai": 87, "Taitong pedestrian Street": 86, "Mingxia Cave": 83, "Jinan": 83, "third Beach": 82, "Qingdao underwater World": 82, "Chunhelou": 79, "Dengzhou Road Beer Street": 74, "Ocean University of China": 74, "Penglai Pavilion": 72, "Huiquan Plaza": 71, "Xuejiadao": 71, "Lao she"s former residence": 65, "Yantai": 63, "Lover Dam": 63, "Jimo": 62, "Liu Gongdao": 60, "Taishan": 58, "Jiaonan": 58, "Zhanshan Temple": 56, "Kang Youwei"s former residence": 54, "Qingdao Olympic Sailing Center": 51, "Rizhao": 51, "long Island": 48, "Zhongtianmen": 44, "Qingdao Museum of posts and Telecommunications": 43, "Taiping Corner Park": 42}
:
![][1]