Wordcloud error

I tried to use this code from this discussion (How to add WordCloud graph in Streamlit - #2 by Amanda_Kelly)

import streamlit as st
from wordcloud import WordCloud
import matplotlib.pyplot as plt

# Create some sample text
text = 'Fun, fun, awesome, awesome, tubular, astounding, superb, great, amazing, amazing, amazing, amazing'

# Create and generate a word cloud image:
wordcloud = WordCloud().generate(text)

# Display the generated image:
plt.imshow(wordcloud, interpolation='bilinear')
plt.axis("off")
plt.show()
st.pyplot()

However, it is not working, it shows the following error: “TypeError: expected string or bytes-like object”.

Could you help me to solve this?

Hey @arthur , you may try this:

fig, ax = plt.subplots()
ax.imshow(wordcloud, interpolation='bilinear')
ax.axis("off")
st.pyplot(fig)

Actually, both your code and mine are working, except that I got some PyplotGlobalUseWarning info when trying yours.

1 Like

Thanks @Sunix_Liu ! It Works!

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.