anaconda3 中 词云无法正常显示

导入需要用到的库

from wordcloud import WordCloud

获取餐厅一列的数据

ww = df['餐厅']

将所有餐厅名字合并成一个字符串

restaurant_names = ' '.join(ww)

使用WordCloud生成词云

wordcloud = WordCloud(width = 800, height = 800,
background_color ='white',
min_font_size = 10).generate(restaurant_names)

绘制词云

plt.figure(figsize = (8, 8), facecolor = None)
plt.imshow(wordcloud)
plt.axis("off")
plt.tight_layout(pad = 0)

plt.show()

AttributeError                            Traceback (most recent call last)

in
9
10 # 使用WordCloud生成词云
---> 11 wordcloud = WordCloud(width = 800, height = 800,
12 background_color ='white',
13 min_font_size = 10).generate(restaurant_names)

D:\app\anaconda\lib\site-packages\wordcloud\wordcloud.py in generate(self, text)
637 self
638 """ 639 return self.generate_from_text(text)
640
641 def _check_generated(self):

D:\app\anaconda\lib\site-packages\wordcloud\wordcloud.py in generate_from_text(self, text)
619 """
620 words = self.process_text(text)
--> 621 self.generate_from_frequencies(words)
622 return self
623

D:\app\anaconda\lib\site-packages\wordcloud\wordcloud.py in generate_from_frequencies(self, frequencies, max_font_size)
451 font_size = self.height
452 else:
--> 453 self.generate_from_frequencies(dict(frequencies[:2]),
454 max_font_size=self.height)
455 # find font sizes

D:\app\anaconda\lib\site-packages\wordcloud\wordcloud.py in generate_from_frequencies(self, frequencies, max_font_size)
506 font, orientation=orientation)
507 # get size of resulting text
--> 508 box_size = draw.textbbox((0, 0), word, font=transposed_font, anchor="lt")
509 # find possible places using integral image:
510 result = occupancy.sample_position(box_size[3] + self.margin,

D:\app\anaconda\lib\site-packages\PIL\ImageDraw.py in textbbox(self, xy, text, font, anchor, spacing, align, direction, features, language, stroke_width, embedded_color)
655 font = self.getfont()
656 mode = "RGBA" if embedded_color else self.fontmode
--> 657 bbox = font.getbbox(
658 text, mode, direct

  AttributeError,意即“属性错误”,由引用对象没有的属性或者方法引发。您的报错在plt.show()后,也就是说plt没有show()方法。请检查拼写错误,亦或者大小写字母不一致,python 对大小写字母敏感,她会认为是不同的字符串。