Python语言学习

Python数据可视化(十三):词云图绘制

2021-07-04  本文已影响0人  Davey1220

使用wordcloud包绘制词云图

# Libraries
from wordcloud import WordCloud
import matplotlib.pyplot as plt

# Create a list of word
text=("Python Python Python Matplotlib Matplotlib Seaborn Network Plot Violin Chart Pandas Datascience Wordcloud Spider Radar Parrallel Alpha Color Brewer Density Scatter Barplot Barplot Boxplot Violinplot Treemap Stacked Area Chart Chart Visualization Dataviz Donut Pie Time-Series Wordcloud Wordcloud Sankey Bubble")
text
'Python Python Python Matplotlib Matplotlib Seaborn Network Plot Violin Chart Pandas Datascience Wordcloud Spider Radar Parrallel Alpha Color Brewer Density Scatter Barplot Barplot Boxplot Violinplot Treemap Stacked Area Chart Chart Visualization Dataviz Donut Pie Time-Series Wordcloud Wordcloud Sankey Bubble'
# Create the wordcloud object
wordcloud = WordCloud(width=480, height=480).generate(text)

# Display the generated image:
plt.imshow(wordcloud, interpolation='bilinear')
plt.axis("off")
plt.margins(x=0, y=0)
plt.show()
image.png
# Create the wordcloud object
# 设置max_font_size=20, min_font_size=10参数更改词云字体的大小范围
wordcloud = WordCloud(width=480, height=480, max_font_size=50, min_font_size=10).generate(text)

# Display the generated image:
plt.imshow(wordcloud, interpolation="bilinear")
plt.axis("off")
plt.margins(x=0, y=0)
plt.show()
image.png
# Create the wordcloud object
# 设置background_color="skyblue"参数更改词云的背景色
wordcloud = WordCloud(width=480, height=480, background_color="skyblue").generate(text)

# Display the generated image:
plt.imshow(wordcloud, interpolation="bilinear")
plt.axis("off")
plt.margins(x=0, y=0)
plt.show()
image.png
# Create the wordcloud object
# 设置colormap="Accent"参数更改词云字体的颜色
wordcloud = WordCloud(width=480, height=480, colormap="Accent").generate(text)

# Display the generated image:
plt.imshow(wordcloud, interpolation="bilinear")
plt.axis("off")
plt.margins(x=0, y=0)
plt.show()
image.png

参考来源:https://www.python-graph-gallery.com/wordcloud/

上一篇下一篇

猜你喜欢

热点阅读