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

Word colors assigned randomly, any way to make them ordered by frequency? #700

Closed n3vrmr closed 1 year ago

n3vrmr commented 1 year ago

Description

I wanted to create a word cloud where the frequency of the words decided their color, as if it was a heatmap of sorts, but I can't figure out how to do it.

wc = WordCloud(background_color='black', stopwords=set(list(STOPWORDS)+additional_stopwords), height=600, width=800, min_font_size=5, max_words=100, colormap=sns.color_palette("Spectral", as_cmap=True), random_state=None)

wc.generate(text) plt.imshow(wc) plt.axis("off") plt.show()

Does the random_state argument do anything? Or should I use a different argument for the colors?

amueller commented 1 year ago

Sorry for the slow response. You can pass a custom color_func that maps the frequency to a color.

xumxum commented 1 year ago

It is right there, in examples/a_new_order.py

amueller commented 1 year ago

Closing, let me know if there's more questions.