Wordcloud Plots not Displaying
My generate_topic_wordcloud() works stand-alone but not in the function: display_similar_topics().
I tried plt.tight_layout(), but that didn't help either.
There are also problems with: display_topics(), display_keywords(). display_similar_words() works properly.
Here's my jupyter lab packages:
% python -c "import sys; print('\n',sys.version); import ipympl; print('ipympl version:', ipympl.__version__)" && jupyter --version && jupyter nbextension list && jupyter labextension list
3.8.5 (default, Sep 4 2020, 02:22:02)
[Clang 10.0.0 ]
ipympl version: 0.9.0
Selected Jupyter core packages...
IPython : 8.2.0
ipykernel : 6.13.0
ipywidgets : 7.7.0
jupyter_client : 7.0.6
jupyter_core : 4.8.1
jupyter_server : 1.11.1
jupyterlab : 3.1.18
nbclient : 0.5.4
nbconvert : 6.2.0
nbformat : 5.1.3
notebook : 6.4.4
qtconsole : not installed
traitlets : 5.1.0
Known nbextensions:
config dir: /Users/davidlaxer/.jupyter/nbconfig
notebook section
jupyter-js-widgets/extension enabled
- Validating: OK
bqplot/extension enabled
- Validating: OK
config dir: /Users/davidlaxer/tensorflow-metal/etc/jupyter/nbconfig
notebook section
catboost-widget/extension enabled
- Validating: OK
jupyter-matplotlib/extension enabled
- Validating: OK
jupyterlab-plotly/extension enabled
- Validating: OK
jupyter-js-widgets/extension enabled
- Validating: OK
JupyterLab v3.1.18
/Users/davidlaxer/tensorflow-metal/share/jupyter/labextensions
jupyter-matplotlib v0.11.0 enabled OK
@jupyter-widgets/jupyterlab-manager v3.1.0 enabled OK (python, jupyterlab_widgets)
Other labextensions (built into JupyterLab)
app dir: /Users/davidlaxer/tensorflow-metal/share/jupyter/lab
jupyterlab-plotly v5.7.0 enabled OK
(tensorflow-metal) (base) davidlaxer@x86_64-apple-darwin13 top2vec %
Any suggestions?
Recently I have noticed it is necessary to plt.show() for wordclouds to display. This will be fixed in the next version.
@ddangelov I think it will be helpful to return a fig object for later use. Also it may be nice to have a fontpath option since we need it to display other languages(like chinese or japanese etc.) I have an example below.
@dbl001 I had a similar problem and I wrote a wrap method to use it in a streamlit app https://github.com/lightondust/top2vec-apps
the method(just a little change from https://github.com/ddangelov/Top2Vec/blob/master/top2vec/Top2Vec.py#L2657-L2704)
def wordcloud(self, word_score_dict, background_color="black"):
fig = plt.figure(figsize=(16, 4),
dpi=200)
plt.axis("off")
additional_input = {}
if self.font_path:
additional_input['font_path'] = self.font_path
plt.imshow(
WordCloud(width=1600,
height=400,
background_color=background_color, **additional_input).generate_from_frequencies(word_score_dict))
return fig
when use
fig = self.model.wordcloud(word_score_dict)
st.pyplot(fig)