zoukankan      html  css  js  c++  java
  • 智联招聘的python岗位数据词云制作

    # 根据传入的背景图片路径和词频字典、字体文件,生成指定名称的词云图片
    def generate_word_cloud(img_bg_path, top_words_with_freq, font_path, to_save_img_path, background_color='white'):
        # 读取背景图形
        img_bg = imread(img_bg_path)
    
        # 创建词云对象
        wc = WordCloud(font_path=font_path,  # 设置字体
                       background_color=background_color,  # 词云图片的背景颜色,默认为白色
                       max_words=100,  # 最大显示词数为1000
                       mask=img_bg,  # 背景图片蒙版
                       max_font_size=50,  # 字体最大字号
                       random_state=30,  # 字体的最多模式
                       width=1000,  # 词云图片宽度
                       margin=5,  # 词与词之间的间距
                       height=700)  # 词云图片高度
    
        # 用top_words_with_freq生成词云内容
        wc.generate_from_frequencies(top_words_with_freq)
    
        # 用matplotlib绘出词云图片显示出来
        plt.imshow(wc)
        plt.axis('off')
        plt.show()
    
        # 如果背景图片颜色比较鲜明,可以用如下两行代码获取背景图片颜色函数,然后生成和背景图片颜色色调相似的词云
        # img_bg_colors = ImageColorGenerator(img_bg)
        # plt.imshow(wc.recolor(color_func = img_bg_colors))
    
        # 将词云图片保存成图片
        wc.to_file(to_save_img_path)
    

      

    调用方法:generate_word_cloud('bg.jpg', top_words_with_freq, 'yahei.ttf', 'santi_cloud.png')
  • 相关阅读:
    mp4的视频打开可以播放在页面上无法打开
    滚动到特定位置菜单固定的效果
    第一次作业
    第一次上机作业
    第一次作业
    第二次作业
    第一次练习作业
    第一次作业
    第三周作业
    第一次JAVA上机练习
  • 原文地址:https://www.cnblogs.com/c-x-a/p/8516679.html
Copyright © 2011-2022 走看看