wordcloud-1.9.2(1.9.3) for python 3.6/python3.X增强补丁

wordcloud-1.9.1开始无法在python3.6和海龟编辑器内正常使用,特做了一个whl 提供给python3.6使用。

另外我自己使用Python3.8 ,因此wordcloud-1.9.2-cp36-cp36-win_amd64.whl  和wordcloud-1.9.3-cp38-cp38-win_amd64.whl,词云图上有前20个单词的频次。

使用效果如图:

修改代码wordcloud.py 

   

    def to_image(self):
        self._check_generated()
        if self.mask is not None:
            width = self.mask.shape[1]
            height = self.mask.shape[0]
        else:
            height, width = self.height, self.width
        x=int(width * self.scale)
        y=int(height * self.scale)
        #高和宽280、200,多出的像素用于存放单词频次
        img = Image.new(self.mode, (x+280,
                                    y+220),
                        self.background_color)
        
        draw = ImageDraw.Draw(img)
        jishu=-1
        words1=''
  
        for (word, count), font_size, position, orientation, color in self.layout_:
            jishu=jishu+1
            
            font = ImageFont.truetype(self.font_path,
                                      int(font_size * self.scale))
            font1 = ImageFont.truetype(self.font_path,
                                      20)                          
            transposed_font = ImageFont.TransposedFont(
                font, orientation=orientation)
            transposed_font1 = ImageFont.TransposedFont(
                font1, orientation=orientation)
            pos = (int(position[1] * self.scale),
                   int(position[0] * self.scale))
                        
            draw.text(pos,word,fill=color,font=transposed_font)
            
            if jishu<21 and x>400:
                
                words1=words1+'  '+word+'..'+str(int(count))
                                              
                if jishu % 5==4:
                    words1=words1.strip()
 
                    draw.text((0,y+jishu*5),words1,fill='red',font=font1)
           
                    words1=''

        return self._draw_contour(img=img)

相关推荐

  1. Python2.x3.x 版本区别

    2024-03-31 09:06:06       22 阅读
  2. python3.x编码解码unicode字符串

    2024-03-31 09:06:06       40 阅读
  3. Linux 升级 Python3.x

    2024-03-31 09:06:06       20 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-03-31 09:06:06       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-03-31 09:06:06       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-03-31 09:06:06       18 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-03-31 09:06:06       20 阅读

热门阅读

  1. pytest中文使用文档----9集成文档测试

    2024-03-31 09:06:06       21 阅读
  2. Linux|如何管理多个Git身份

    2024-03-31 09:06:06       18 阅读
  3. wifi密码,pc端

    2024-03-31 09:06:06       17 阅读
  4. git commit message 规范

    2024-03-31 09:06:06       16 阅读
  5. git总结

    2024-03-31 09:06:06       17 阅读
  6. MindOpt APL向量化建模语法的介绍与应用(1)

    2024-03-31 09:06:06       15 阅读