美文网首页Python语言学习
Python数据可视化(十三):词云图绘制

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

作者: Davey1220 | 来源:发表于2021-07-04 15:58 被阅读0次

    使用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/

    相关文章

      网友评论

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

        本文链接:https://www.haomeiwen.com/subject/zyamultx.html