使用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
网友评论