使用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()
# Create the wordcloud object
# 設(shè)置max_font_size=20, min_font_size=10參數(shù)更改詞云字體的大小范圍
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()
# Create the wordcloud object
# 設(shè)置background_color="skyblue"參數(shù)更改詞云的背景色
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()
# Create the wordcloud object
# 設(shè)置colormap="Accent"參數(shù)更改詞云字體的顏色
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()
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者