词云图python代码
时间: 2023-06-22 08:17:26 浏览: 63
以下是一个简单的Python代码示例,用于生成词云图:
```python
# 导入需要的库
from wordcloud import WordCloud
import matplotlib.pyplot as plt
# 定义文本
text = "Python是一种高级编程语言,它被广泛应用于数据科学、人工智能、Web开发等领域。"
# 创建WordCloud对象
wordcloud = WordCloud(width=800, height=400, background_color='white').generate(text)
# 绘制词云图
plt.imshow(wordcloud, interpolation='bilinear')
plt.axis("off")
plt.show()
```
在这个示例中,我们使用WordCloud库创建了一个WordCloud对象,并使用generate()方法传入一个文本字符串来生成词云图。我们还设置了词云图的宽度、高度和背景颜色。最后,我们使用Matplotlib库将词云图绘制出来,并禁用了坐标轴。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![tar](https://img-home.csdnimg.cn/images/20210720083646.png)
![pptx](https://img-home.csdnimg.cn/images/20210720083543.png)