Creating Word cloud

223 views Asked by At

I tried building a wordcloud on my jupyter notebook with the code

from wordcloud import WordCloud
import matplotlib.pyplot as plt

sent = "This is my First Word Cloud, it is the First of its kind, and your First Word Cloud is always the most amazing"

wc = WordCloud(font_path =r'C:\Users\DELL\AppData\Local\Microsoft\Windows\Fonts\FiraSans-Thin.ttf').generate(sent)

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

it keeps returning an error"

ValueError: Only supported for TrueType fonts

I tried downloading and installing new fonts from googlefonts, i also tried using pycharm but the errror was still the same

1

There are 1 answers

0
Michel On

Extract the font to your project folder (e.g. ./font/Fira_Sans) and load it from there.

from os import path

d = path.dirname(__file__) if "__file__" in locals() else os.getcwd()

font_path = path.join(d, 'fonts', 'Fira_Sans', 'FiraSans-Thin.ttf')

wc = WordCloud(font_path=font_path).generate(sent)

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