amueller / word_cloud

A little word cloud generator in Python
https://amueller.github.io/word_cloud
MIT License
10.1k stars 2.31k forks source link

Generating a wordcloud from a dictionary of terms with their frequencies #754

Closed rjalexa closed 9 months ago

rjalexa commented 9 months ago

not a bug but rather a question/request

I have a complex word routine that extracts relevant terms from a text, it is based on the Part of Speech and another couple of NLP routines.

I generate a dictionary as follows: {"term1": 12, "term2": 6 ..... } where "term1" is one of the words selected from my source text and the value is its frequency in it.

Is there any way to feed this structure so that it takes the frequency to determine the size and build the wordcloud from it?

Happy 2024

rjalexa commented 9 months ago

Sorry found this is already supported:

Extracting just the frequencies from the result dictionary

word_frequencies = {word: data["count"] for word, data in result.items()}

# Create a WordCloud object
wordcloud = WordCloud(
    width=800, height=400, background_color="white"
).generate_from_frequencies(word_frequencies)