在使用 WordCloud 库生成词云时,可能会遇到 AttributeError: 'ImageDraw' object has no attribute 'textbbox' 错误。这个错误通常是由于 WordCloud 库版本问题引起的。

以下两种方法可以尝试解决:

  1. 升级 WordCloud 库:

    建议尝试升级 WordCloud 库到最新版本。可以通过以下命令升级:

pip install --upgrade wordcloud


2. **添加停用词:**

   在生成词云时,尝试加入 `stopwords` 参数,过滤一些常用词语,减少可能出现的错误。例如:

   ```python
wc = WordCloud(fontpath='STCAIYUN.TTF', backgroundcolor='white', width=1000, height=800, stopwords={'the', 'and', 'of'}).generate(' '.join(new_data))

如果以上方法都不能解决问题,建议参考 WordCloud 库的官方文档或寻求更专业的技术支持。

解决 'AttributeError: 'ImageDraw' object has no attribute 'textbbox''  词云显示错误

原文地址: https://www.cveoy.top/t/topic/oAIC 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录