Ejemplo n.º 1
0
 def draw_dictionary(self, dictionary):
     dictionary = self.sort_dictionary()
     c = (WordCloud().add("", dictionary, word_size_range=[
         20, 100
     ]).set_global_opts(title_opts=opts.TitleOpts(title="HUAWEIP30评论高频词")))
     WordCloud.render(c,
                      self.get_desktop() + "\\jd.huaweiP30.comments.html")
     return True
Ejemplo n.º 2
0
def generateWoldCloud(keyPhrases):
    """
    generate the word cloud to make the key-phrases visual

    :param keyPhrases:  in format of [(content, frequency),...)]
    :return: WordCloud
    """
    logger.debug("Start to generate the WoldCloud")
    myWordCloud = WordCloud()
    myWordCloud.add('', keyPhrases, shape='circle')
    return myWordCloud
Ejemplo n.º 3
0
def wc():
    myWordCloud = WordCloud("绘制词云", width=1000, height=620)
    name = ['Sam S Club', 'Macys', 'Amy Schumer', 'Jurassic World',
            'Charter Communications', 'Chick Fil A', 'Planet Fitness', 'Pitch Perfect',
            'Express', 'Home', 'Johnny Depp', 'Lena Dunham',
            'Lewis Hamilton', 'KXAN', 'Mary Ellen Mark', 'Farrah Abraham',
            'Rita Ora', 'Serena Williams', 'NCAA baseball tournament', 'Point Break']
    value = [10000, 6181, 4386, 4055, 2467, 2244, 1898, 1484, 1112, 965,
             847, 582, 555, 550, 462, 366, 360, 282, 273, 265]
    myWordCloud.add("", name, value, word_size_range=[20, 100])
    return myWordCloud.render_embed()
Ejemplo n.º 4
0
def tag_words_chart():
    tag_words_dict = {}

    for t in Tag.objects.order_by('-number')[:300]:
        tag_words_dict[t.name.lower()] = tag_words_dict.get(t.name.lower(), 0) + t.number
    word_cloud = WordCloud(
        init_opts=opts.InitOpts(
            height='700%', width='1100px',
            js_host='../static/js/',
        )
    ).add("", tag_words_dict.items(), word_size_range=[20, 100], shape=SymbolType.RECT)
    return word_cloud.render_embed()
Ejemplo n.º 5
0
def drawWordCloud(words, name):
    # 图表初始化配置
    init_opts = opts.InitOpts(page_title=name)

    wc = WordCloud(init_opts=init_opts)
    # 标题配置
    title = opts.TitleOpts(title=name, pos_left="50%")
    toolbox_opts = opts.ToolboxOpts(
        orient="vertical",
        pos_bottom="40%",
        pos_left="90%",
    )

    wc.set_global_opts(
        title_opts=title,
        toolbox_opts=toolbox_opts,
    )
    wc.add(
        "",
        words,
        word_size_range=[20, 300],
        shape="diamond",
        textstyle_opts=opts.TextStyleOpts(font_family="cursive"),
    )
    wc.render("{0}.html".format(name))
Ejemplo n.º 6
0
def ci_yun():
    wordcloud = WordCloud()
    new = list(zip(data['省区平台'], k))
    words = new
    wordcloud.add("", words, word_size_range=[20, 100], shape="diamond")
    wordcloud.set_global_opts(title_opts=opts.TitleOpts(title="热销平台"))
    wordcloud.render("../graph/5.4(热销平台).html")
Ejemplo n.º 7
0
def word():
    w = WordCloud()

    import jieba
    txt = ''
    with open('data.csv', 'r') as f:
        reader = csv.reader(f)
        for row in reader:
            txt += filter_emoji(row[0]).replace('[', '').replace(
                ']', '').replace(' ',
                                 '').replace(' ',
                                             '').replace("'",
                                                         '').replace(',', '')
    txt = jieba.lcut(txt)

    count = {}
    for wo in txt:
        if wo in count:
            count[wo] += 1
        else:
            count[wo] = 1

    w.add(series_name="热点分析",
          data_pair=list(count.items()),
          word_size_range=[6, 66])

    w.set_global_opts(
        title_opts=opts.TitleOpts(
            title="热点分析",
            title_textstyle_opts=opts.TextStyleOpts(font_size=23)),
        tooltip_opts=opts.TooltipOpts(is_show=True),
    )
    w.render()
Ejemplo n.º 8
0
 def ci_yun(self, your_id, your_data):
     new = list(zip(your_id, your_data))
     words = new
     wordcloud = WordCloud(
         init_opts=opts.InitOpts(width="1920px", height='960px'))
     wordcloud.add('', words, word_size_range=[20, 100])
     wordcloud.set_global_opts(title_opts=opts.TitleOpts(title='新型冠状病毒词云图'))
     wordcloud.render(self.filename + "词云图.html")
Ejemplo n.º 9
0
def show_word_charts():
    word1 = WordCloud(init_opts=opts.InitOpts(width='1350px', height='750px'))
    word1.add("", [*zip(key_words.words, key_words.num)],
              word_size_range=[20, 200],
              shape=SymbolType.DIAMOND)
    word1.set_global_opts(title_opts=opts.TitleOpts('完美关系豆瓣短评词云图'),
                          toolbox_opts=opts.ToolboxOpts())
    word1.render()
Ejemplo n.º 10
0
def generate_word_cloud(word_list, path_name=None):
    wordcloud = WordCloud()
    wordcloud.add('词云图',
                  tuple(zip(word_list.index, word_list)),
                  word_size_range=[20, 100])
    wordcloud.set_global_opts(title_opts=opts.TitleOpts(title='电影评论'))
    wordcloud.render(path=path_name)
    print(f'Generate word cloud file done: {path_name}')
Ejemplo n.º 11
0
 def wordcloud(self, name=None, values=None, width=1200, height=620):
     """
     词云图
     :param name: 词云列表
     :param values: 词云列表权重值,与词云列表对应
     :param width: 宽度默认1200
     :param height: 高度默认600
     :return:词云图
     """
     name = name
     value = values
     wordcloud = WordCloud(width, height)
     wordcloud.add('', name, value, word_size_range=[20, 100])
     self.page.add(wordcloud)
     self.page.render()
Ejemplo n.º 12
0
def get_cloud_word():
    source_url='E:\\PythonProjects\\weibo-crawler-master\\res\\weibo\\人民日报\\2803301701.csv';
    target_url='E:\\PythonProjects\\weibo-crawler-master\\res\\weibo\\人民日报';
    with open(source_url,'r',encoding='utf-8',newline='') as file:
        reader=csv.reader(file)
        huati_content={}#用来储存所有话题微博
        haoyou_content={}#用来储存所有@的好友
        for line in reader:
            if line[9]:
                if line[9]!='话题':
                    for usr in str(line[9]).split(','):
                        #print(usr)#测试成功
                        ##利用字典,对字典进行++操作
                        if usr in huati_content.keys():
                            huati_content[usr]+=1
                        else :
                            huati_content[usr]=0
            if line[10]:
                if line[10]!='@用户':
                    for usr in str(line[10]).split(','):
                        if usr in haoyou_content.keys():
                            haoyou_content[usr]+=1
                        else:
                            haoyou_content[usr]=0
    huati_words=[]
    haoyou_words=[]
    for w ,t in huati_content.items():
        if t>0:
            huati_words.append((w,t))
    for w,t in haoyou_content.items():
        if t>0:
            haoyou_words.append((w,t))
# 词云图轮廓,有 'circle', 'cardioid', 'diamond', 'triangle-forward', 'triangle', 'pentagon', 'star' 可选
    shapes=['circle', 'cardioid', 'diamond', 'triangle-forward', 'triangle', 'pentagon', 'star']#7个
    shape=shapes[random.randint(0,7)]
    huati_wc = (
        WordCloud(init_opts=opts.InitOpts(width="1600px", height="700px",theme='vintage',page_title="博主话题词云图"))
        .add("", huati_words, word_size_range=[20, 100],shape=shape)
        .set_global_opts(title_opts=opts.TitleOpts(title="博主话题词云库"))
    )
    huati_wc.render("博主话题词云图.html")
    shape=shapes[random.randint(0,7)]
    haoyou_wc = (
        WordCloud(init_opts=opts.InitOpts(width="1600px", height="700px",theme='vintage',page_title="博主@的用户词云图"))
        .add("", haoyou_words, word_size_range=[20, 100],shape=shape)
        .set_global_opts(title_opts=opts.TitleOpts(title="博主话题词云图"))
    )
    haoyou_wc.render("博主好友词云图.html")
def wordcloud_base() -> WordCloud:
    c = (
        WordCloud()
        .add("", words, word_size_range=[20, 100], shape = 'diamond')
        .set_global_opts(title_opts=opts.TitleOpts(title=""))
    )
    return render_template('ciyun.html')
Ejemplo n.º 14
0
def wordcloud_base() -> WordCloud:
    c = (
        WordCloud()
        .add("", words, word_size_range=[20, 100], shape=SymbolType.ROUND_RECT)
        .set_global_opts(title_opts=opts.TitleOpts(title='全国新型冠状病毒疫情词云图'))
    )
    return c
Ejemplo n.º 15
0
def wordcloud_base() -> WordCloud:
    c = (
        WordCloud()
        .add("", words, word_size_range=[20, 40], shape='diamond') #shape=SymbolType.ROUND_RECT
        .set_global_opts(title_opts=opts.TitleOpts(title='词云图'))
    )
    return c
Ejemplo n.º 16
0
def make_wordcloud():
    sourceTxt = 'wordcloud/data/test.txt'
    source1Txt = 'wordcloud/data/test1.txt'
    targetTxt = 'wordcloud/data/target.txt'

    jieba.analyse.set_stop_words('wordcloud/data/baidu_stopwords.txt')
    with open(sourceTxt, 'r', encoding='utf-8') as sourceFile, open(
            source1Txt, 'a+', encoding='utf-8') as targetFile:
        pattern = re.compile(r'[^\u4e00-\u9fa5]')
        for line in sourceFile:
            # seg = jieba.cut(line.strip(), cut_all = False)
            # 分好词之后之间用空格隔断
            output = re.sub(pattern, "", line)
            targetFile.write(output)
            targetFile.write('\n')

    words = []  # 可以存储生成词云的数据

    # 对文本进行操作
    with open(source1Txt, 'r', encoding='utf-8') as sourceFile, open(
            targetTxt, 'a+', encoding='utf-8') as targetFile:
        for line in sourceFile:
            seg = jieba.cut(line.strip(), cut_all=False)
            # 分好词之后之间用空格隔断
            output = ' '.join(seg)
            targetFile.write(output)
            targetFile.write('\n')
        print('ycl写入成功!')

    keywords = []

    with open(targetTxt, 'r', encoding='utf-8') as file:
        text = file.readlines()
        """
        几个参数解释:
            * text : 待提取的字符串类型文本
            * topK : 返回TF-IDF权重最大的关键词的个数,默认为20个
            * withWeight : 是否返回关键词的权重值,默认为False
            * allowPOS : 包含指定词性的词,默认为空
        """
        keywords = jieba.analyse.extract_tags(str(text),
                                              topK=30,
                                              withWeight=True,
                                              allowPOS=())
        print(keywords)
        for i in keywords:
            a = i[0]
            b = float(i[1]) * 100
            words.append((a, b))
        print(words)

    a = (WordCloud().add(
        series_name="ycl热点分析", data_pair=keywords,
        word_size_range=[20, 80]).set_global_opts(
            title_opts=opts.TitleOpts(
                title="热点分析",
                title_textstyle_opts=opts.TextStyleOpts(font_size=23)),
            tooltip_opts=opts.TooltipOpts(is_show=True),
        ))
    return a.render_embed()
Ejemplo n.º 17
0
def bar_base(id):
    answer = getSummaryFunction(id)
    jsons = []
    for item in answer['answer']:
        if item['type'] == '多选' or item['type'] == '单选':
            c = (Bar().add_xaxis(eval(item['option'])).add_yaxis(
                "",
                eval(item['number']),
                category_gap="80%",
                color=Faker.rand_color()).set_global_opts(
                    title_opts=opts.TitleOpts(title=item['questionName'],
                                              subtitle=""),
                    toolbox_opts=opts.ToolboxOpts()).dump_options_with_quotes(
                    ))
            jsons.append(c)
        else:
            words = {}
            for i in eval(item['content']):
                if i not in words.keys():
                    words[i] = 1
                else:
                    words[i] += 1
            c = (WordCloud().add(
                "", list(words.items()),
                word_size_range=[20, 100]).set_global_opts(
                    title_opts=opts.TitleOpts(title=item['questionName']),
                    toolbox_opts=opts.ToolboxOpts()).dump_options_with_quotes(
                    ))
            jsons.append(c)
    return jsons
Ejemplo n.º 18
0
def wordcloud_base() -> WordCloud:
    c = (
        WordCloud()
        .add("", words, word_size_range=[20, 100])
        .set_global_opts(title_opts=opts.TitleOpts(title="WordCloud-基本示例"))
    )
    return c
Ejemplo n.º 19
0
def ciyun_en(movie_name):
    #读取数据
    filename = movie_name + '\\' + movie_name + 'Dreview.txt'
    with open(filename, 'r+', encoding='utf-8') as f:
        rev_1 = f.read()
        #处理标点
        for i in rev_1:
            if i in string.punctuation:
                rev_1 = rev_1.replace(i, " ")
        #分词+统计
        words = rev_1.split()
        words_dic = Counter(words)
    #删除一些高频词
    file_del = 'ban.txt'
    with open(file_del, 'r+', encoding='utf-8') as d:
        del_1 = d.read()
        Ban_list = del_1.split('\n')
    #处理数据
    words_list = []
    for word, time in words_dic.items():
        if word.lower() in Ban_list or time < 35:
            continue
        else:
            a_word = (word.title(), time)
            words_list.append(a_word)
    #出图
    words_cloud = (WordCloud().add(
        "", words_list, word_size_range=[20, 100],
        shape="diamond").set_global_opts(
            title_opts=opts.TitleOpts(title=movie_name + " WordCloud",
                                      subtitle=None),
            toolbox_opts=opts.ToolboxOpts(is_show=True)))
    words_cloud.render(movie_name + '\\' + movie_name + 'wordcloud.html')
Ejemplo n.º 20
0
def wordcloud():
    latest_time = os.path.getmtime("C:\\Users\\natuk\\Desktop\\北大\\计算机科学与编程入门\\1700091817_翁雨音_final\\zhihu_hot.txt")  # Unix时间
    latest_time = time.localtime(latest_time)
    latest_time = time.strftime("%Y-%m-%d %H:%M:%S", latest_time) #转换为年-月-日-时-分-秒的形式
    latest_time = str(latest_time)
    #  print(latest_time)

    data = []
    
    with open("C:\\Users\\natuk\\Desktop\\北大\\计算机科学与编程入门\\1700091817_翁雨音_final\\zhihu_hot.txt", 'r', encoding='utf-8') as f:
        lines = f.readlines()
        for line in lines:
            s1 = line.split('.')[1] # 去掉序号
            title = s1.split('(')[0]
            s2 = s1.split('(')[1]
            amount_s = s2.split('万热度')[0]
            amount = int(amount_s)
            #print(title, amount)
            data.append((title,amount))
                    
    #print(data)
            
    
    (
        WordCloud()
        .add(series_name="热点分析", data_pair=data, word_size_range=[6, 66])
        .set_global_opts(
            title_opts=opts.TitleOpts(title="热点分析 更新于 " + latest_time, 
                                      title_textstyle_opts=opts.TextStyleOpts(font_size=23)),
            tooltip_opts=opts.TooltipOpts(is_show=True),
        )
        .render("zhihu_wordcloud.html")
    )
Ejemplo n.º 21
0
def wordcloud_base(words) -> WordCloud:
    c = (
        WordCloud().add("", words, word_size_range=[
            20, 80
        ])  # words的格式为[("Sam S Club", 10000),("Macys", 6181)], 后面的参数代表字的大小范围
        .set_global_opts(title_opts=opts.TitleOpts(title="疫情词云")))
    return c
Ejemplo n.º 22
0
def wordcloud_base() -> WordCloud:
    c = (WordCloud().add("",
                         data_cloud[0:],
                         word_size_range=[12, 100],
                         shape=SymbolType.DIAMOND).set_global_opts(
                             title_opts=opts.TitleOpts(title="词云")))
    return c
Ejemplo n.º 23
0
def wordcloud_base() -> WordCloud:
    c = (
        WordCloud()
        .add("", chinas[:100], word_size_range=[20, 100])
        .set_global_opts(title_opts=opts.TitleOpts(title="岗位要求"))
    )
    return c
Ejemplo n.º 24
0
def wordcloud_user_job_base():
    """
    It is used to respond to requests for chart parameters.

    Returns
    -------
    c : TYPE-echarts parameters
        return echarts parameters.

    """
    
    # data query
    data_pair = user_job_wordcloud_freq_query()
    # Declare objects, render pictures
    c = (
        WordCloud()
        .add(series_name="Occupation", data_pair=data_pair, word_size_range=[10,100],
             shape="cicle", width="1200", height="800",)
        .set_global_opts(
                         title_opts=opts.TitleOpts(title="User Occupation Analysis", pos_left="center",
                                                   title_textstyle_opts=opts.TextStyleOpts(font_size=23)),
                         tooltip_opts=opts.TooltipOpts(is_show=True),
                         )
        )
    return c
Ejemplo n.º 25
0
def wordcloud():
    data = []
    f = random.randint(0, 10)
    t = random.randint(20, 30)
    type_models = list(SubType.objects.order_by('?')[f:t])
    main_models = list(MainType.objects.order_by('?')[f:t])
    sub_models = list(SubType.objects.order_by('?')[f:t])
    dis_models = list(District.objects.order_by('?')[f:t])
    str_models = list(Street.objects.order_by('?')[f:t])
    com_models = list(Community.objects.order_by('?')[f:t])

    models = type_models + main_models + sub_models + dis_models + com_models + str_models

    for model in models:
        data.append((str(model.name), str(model.number)))

    print(data)

    c = (
        WordCloud().add(
            series_name="wordcloud", data_pair=data,
            word_size_range=[20, 200]).set_global_opts(
                title_opts=opts.TitleOpts(
                    title='',
                    title_textstyle_opts=opts.TextStyleOpts(font_size=23)),
                tooltip_opts=opts.TooltipOpts(is_show=True),
            ).dump_options_with_quotes()
        # .render("basic_wordcloud.html")
    )
    return c
Ejemplo n.º 26
0
def wordcloud_diamond() -> WordCloud:
    c = (
        WordCloud()
        .add("", words, word_size_range=[20, 100], shape=SymbolType.DIAMOND)
        .set_global_opts(title_opts=opts.TitleOpts(title="WordCloud-shape-diamond"))
    )
    return c
Ejemplo n.º 27
0
 def show_comment(self):
     alls = AnalyzeComment.objects.all().order_by('-counts')
     lans = ("zh", "en")
     tags = ("", "v", "n", "a")
     for lan in lans:
         for tag in tags:
             file = "analysis/%s_%s.html" % (lan, tag)
             if not tag:
                 objs = alls[:200]
             else:
                 objs = alls.filter(tag=tag)[:200]
             if lan == "zh":
                 data = [(item.word, item.counts) for item in objs]
             else:
                 data = [(item.word_en, item.counts) for item in objs]
     # render 会生成本地 HTML 文件,默认会在当前目录生成 render.html 文件
     # 也可以传入路径参数,如 bar.render("mycharts.html
             (WordCloud().add(
                 series_name="word analysis",
                 data_pair=data,
                 word_size_range=[10, 200]).set_global_opts(
                     title_opts=opts.TitleOpts(
                         title="word frequency",
                         title_textstyle_opts=opts.TextStyleOpts(
                             font_size=23)),
                     tooltip_opts=opts.TooltipOpts(is_show=True),
                 ).render(file))
Ejemplo n.º 28
0
def plot_word_cloud_maoyan(data, swords, path):

    text = ''
    # 将所有评论连接起来,以便于jieba切分词语
    for temp_i in data['content']:
        text += str(temp_i)

    words = list(jieba.cut(text))
    ex_sw_words = []
    for word in words:
        if len(word) > 1 and (word not in swords):
            ex_sw_words.append(word)
    c = Counter()
    c = Counter(ex_sw_words)
    # 计算所有评论中词语的出现频率
    wc_data = pd.DataFrame({
        'word': list(c.keys()),
        'counts': list(c.values())
    }).sort_values(by='counts', ascending=False).head(100)
    # print(wc_data)

    # 绘制猫眼对应的高分和低分词云
    c = (WordCloud().add("",
                         wc_data.values,
                         word_size_range=[20, 100],
                         shape=SymbolType.DIAMOND).set_global_opts(
                             title_opts=opts.TitleOpts(title=path)))

    return c
Ejemplo n.º 29
0
def wordcloud_diamond() -> WordCloud:
    words = [
        ("Sam S Club", 10000),
        ("Macys", 6181),
        ("Amy Schumer", 4386),
        ("Jurassic World", 4055),
        ("Charter Communications", 2467),
        ("Chick Fil A", 2244),
        ("Planet Fitness", 1868),
        ("Pitch Perfect", 1484),
        ("Express", 1112),
        ("Home", 865),
        ("Johnny Depp", 847),
        ("Lena Dunham", 582),
        ("Lewis Hamilton", 555),
        ("KXAN", 550),
        ("Mary Ellen Mark", 462),
        ("Farrah Abraham", 366),
        ("Rita Ora", 360),
        ("Serena Williams", 282),
        ("NCAA baseball tournament", 273),
        ("Point Break", 265),
    ]
    c = (WordCloud().add(
        "", words, word_size_range=[20, 100],
        shape=SymbolType.DIAMOND).set_global_opts(title_opts=opts.TitleOpts(
            title="WordCloud-shape-diamond")))
    return c
Ejemplo n.º 30
0
	def wordcloud_base(tem_list,tem_num_list) -> WordCloud:
		c = (
			WordCloud(init_opts = opts.InitOpts(width = "900px", height = "550px", theme=ThemeType.ROMA))
			.add("", zip(tem_list,tem_num_list), word_size_range=[20, 120], shape=SymbolType.DIAMOND)
			.set_global_opts(title_opts=opts.TitleOpts(title="{}地区 {} 岗位工作福利".format(area,jobkey),))
		)
		return c