Skip to content
Advertisement

Increase resolution with word-cloud and remove empty border

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.

JavaScript

Advertisement

Answer

You can’t increase the resolution of the image in plt.show() since that is determined by your screen, but you can increase the size. This allows it to scale, zoom, etc. without blurring. To do this pass dimensions to WordCloud, e.g.

JavaScript

However, this just determines the size of the image created by WordCloud. When you display this using matplotlib it is scaled to the size of the plot canvas, which is (by default) around 800×600 and you again lose quality. To fix this you need to specify the size of the figure before you call imshow, e.g.

JavaScript

By doing this I can successfully create a 2000×1000 high resolution word cloud.

For your second question (removing the border) first we could set the border to black, so it is less apparent, e.g.

JavaScript

You can also shrink the size of the border by using tight_layout, e.g.

JavaScript

The final code:

JavaScript

By replacing the last two lines with the following you can get the final output shown below:

JavaScript

final Constitution wordcloud

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement