Home > database >  Python export wordcloud to pdf
Python export wordcloud to pdf

Time:12-07

I would like to export a wordcloud to pdf instead of png in order not to lose quality when zooming in. Is that feasible, since the wordcloud is already a picture itself ?

This is what I tried:

wc = WordCloud(max_font_size=120, max_words= 100, background_color="white", height=600,width=800)
wc = wc.generate_from_frequencies(mdict)

plt.imshow(wc, interpolation='bilinear')
plt.axis("off")
plt.show()

wc.to_file(outputpath   "test.pdf")

But it returns a pdf with a picture in a bitmap format, just like a png picture. I would like to get the picture in a true pdf format (vectorial format).

Edit: wording

CodePudding user response:

By nature of to_file you get RGB image file (set mode for with or without alpha) however see the to_svg option since version 1.7.0, you then need of course svg to pdf! (easily done using browser to pdf)

to_array()                                       Convert to numpy array.

to_file(filename)                                Export to image file.

to_svg([embed_font, optimize_embedded_font, …])  Export to SVG.
  • Related