Increase resolution with word-cloud and remove empty border

后端 未结 4 458
北海茫月
北海茫月 2020-12-23 14:06

I am using word cloud with some txt files. How do I change this example if I wanted to 1) increase resolution and 2) remove empty border.

#!/usr/bin/env pyt         


        
4条回答
  •  佛祖请我去吃肉
    2020-12-23 15:12

    If you are trying to use an image as a mask, make sure to use a big image to get better image quality.. I spent hours figuring this out.

    Heres an example of a code snippet I used

    mask = np.array(Image.open('path_to_your_image'))
    image_colors = ImageColorGenerator(mask)
    wordcloud = WordCloud(width=1600, height=800, background_color="rgba(255, 255, 255, 0)", mask=mask
                         ,color_func = image_colors).generate_from_frequencies(x)
    
    # Display the generated image:
    plt.figure( figsize=(20,10) )
    plt.imshow(wordcloud, interpolation='bilinear')
    plt.axis("off")
    

提交回复
热议问题