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)

上一篇:Qt 作业 24/3/26


下一篇:pandas在循环中多次写入数据到一个excel防止锁定的方法