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')
  • 相关阅读:
    DELPHI 各版本下载
    一个好的网站,学习前端
    没那么难,谈CSS的设计模式
    一个前端的自我修养
    如何学习Javascript
    jQuery WeUI V0.4.2 发布
    微信官方开源UI库-WeUI
    js与php传递参数
    ?js调用PHP里的变量,怎么弄?
    Liferay7 BPM门户开发之23: 了解内置工作流(Kaleo Workflow)
  • 原文地址:https://www.cnblogs.com/c-x-a/p/8516679.html
Copyright © 2011-2022 走看看