2

Suppose I have a string for which I want to make a word cloud, like so:

from wordcloud import WordCloud
import matplotlib.pyplot as plt

teststring = 'hi this is a test test test test test string for a word cloud'
wordcloud = WordCloud(width=1000, height=1000, margin=0, background_color='white', 
                      collocations=False).generate(teststring)
plt.imshow(wordcloud)

Furthemore I have made a bokeh Tabs object with a few tabs

from bokeh.plotting import figure, output_file, show
from bokeh.models.widgets import Panel, Tabs

output_file('stackoverflow.html')
p1 = figure()
p1.line(x=range(5), y=range(5))
tab1 = Panel(child=p1, title="Line plot")
tabs = Tabs(tabs=[tab1])
show(tabs)

How can I add the figure of the wordcloud to a tab2, to show in the panel?

I've looked at many links (such as), but couldn't get it to work. The closes I found was here: How do I work with images in Bokeh (Python), but for this to work, it seems I have to save the wordcloud intermediately (in fact I have ~25 of them). Is that really necessary, or can I also immediately show the wordcloud in bokeh?

Thanks in advance!

Jondiedoop
  • 3,303
  • 9
  • 24

1 Answers1

1

shameless plug ... I just wrote a wordcloud plugin for bokeh

https://github.com/joranbeasley/bokeh_wordcloud2

Here is an example using it with one big chunk of text

from bokeh_wordcloud2 import WordCloud2

source = ColumnDataSource(data={'x':[my_text]})
wordcloud = WordCloud2(source=source,wordCol='x',colors='blue')
curdoc().add_root(wordcloud)
Joran Beasley
  • 110,522
  • 12
  • 160
  • 179
  • I am not able to get `bokeh_wordcloud2` to work with bokeh, getting this error as mentioned in the [link](https://stackoverflow.com/questions/71953832/unsetvalueerror-while-plotting-wordcloud-using-bokeh-package?noredirect=1#comment127180470_71953832) – nikhil int Apr 25 '22 at 11:32