WordCloud in Plotly (Interactive!)
Last Updated: 08 Nov 2025
WordCloud shows word frequency with size — perfect for text analysis, reviews, tweets, surveys, or NLP insights.
Plotly has no built-in WordCloud, but we hack it with wordcloud + px.imshow() → zoom, hover, save, embed — fully interactive!
Hinglish Tip:
WordCloud = "jis word ka size bada, woh zyada important" — jaise news headline!
Install Once
pip install wordcloud plotly
Basic WordCloud (Interactive)
import plotly.express as px
from wordcloud import WordCloud
import matplotlib.pyplot as plt
# Sample text
text = """
Python JavaScript Java C++ HTML CSS React Node Express Django Flask
Pandas NumPy Matplotlib Seaborn Plotly Dash Streamlit FastAPI
Machine Learning AI Deep Learning NLP Computer Vision Data Science
"""
# Generate WordCloud
wc = WordCloud(
width=1000,
height=600,
background_color='white',
colormap='plasma',
min_font_size=10
).generate(text)
# Convert to image array
img = wc.to_array()
# Show in Plotly (Interactive!)
fig = px.imshow(img)
fig.update_layout(
title="Programming Languages WordCloud",
coloraxis_showscale=False,
margin=dict(l=0, r=0, t=40, b=0)
)
fig.show()
Interactive: Zoom in, pan, hover (pixel values), save as PNG/HTML!
Key Parameters in WordCloud()
| Parameter | Values | Purpose |
|---|---|---|
|
| Image size |
background_color |
| Background |
colormap |
| Color scheme |
min_font_size | 10 | Smallest word size |
max_words | 100 | Limit words |
mask | np.array(Image.open('mask.png')) | Shape (heart, India, etc.) |
|
| Border around shape |
Full Example: Movie Reviews (With Mask & Dark Mode)
import plotly.express as px
from wordcloud import WordCloud
import numpy as np
from PIL import Image
# Sample movie review text
text = """
amazing brilliant outstanding masterpiece epic emotional powerful
touching heartwarming funny hilarious entertaining blockbuster
cinema art director actor performance script music soundtrack
visual effects cinematography storytelling plot twist climax
"""
# Optional: Heart-shaped mask
mask = np.array(Image.open("heart.png")) # Download a heart mask PNG
wc = WordCloud(
width=1200, height=800,
background_color='#0e1117', # Dark mode
colormap='magma',
mask=mask,
contour_width=3,
contour_color='orange',
max_words=80,
min_font_size=12
).generate(text)
fig = px.imshow(wc.to_array())
fig.update_layout(
title="Movie Reviews WordCloud (Heart Shape + Dark Mode)",
coloraxis_showscale=False,
margin=dict(t=50)
)
fig.show()
Hinglish Tip:
mask=heart.png → dil ke shape mein words — perfect for Valentine's or feedback!
From Real Data (Pandas + Frequency)
import pandas as pd
# Sample feedback data
df = pd.DataFrame({
'review': ['great product fast delivery', 'poor quality bad service',
'amazing value for money', 'highly recommend excellent']
})
# Count word frequency
from collections import Counter
all_text = ' '.join(df['review'])
word_freq = Counter(all_text.split())
# Generate from dictionary
wc = WordCloud(width=1000, height=500, background_color='white').generate_from_frequencies(word_freq)
fig = px.imshow(wc.to_array())
fig.update_layout(title="Customer Feedback WordCloud")
fig.show()
Save Interactive WordCloud
# Interactive HTML (zoom + pan!)
fig.write_html("wordcloud_interactive.html")
# High-quality PNG
fig.write_image("wordcloud.png", engine="kaleido", width=1200, height=800, scale=3)
Hinglish Tip:
scale=3 → super sharp for reports, slides, websites!
Install:
pip install -U kaleido
Bonus: Live WordCloud in Dash (Dropdown)
from dash import Dash, dcc, html, Input, Output
import plotly.express as px
from wordcloud import WordCloud
app = Dash(__name__)
app.layout = html.Div([
html.H1("Live WordCloud Generator"),
dcc.Dropdown(
id='topic',
options=['Python', 'Cricket', 'Food', 'Travel'],
value='Python'
),
dcc.Graph(id='wc-graph')
])
@app.callback(
Output('wc-graph', 'figure'),
Input('topic', 'value')
)
def update_wordcloud(topic):
texts = {
'Python': "Python Dash Plotly Pandas NumPy AI ML FastAPI Streamlit Code Data",
'Cricket': "IPL Rohit Virat Dhoni Kohli Bumrah Six Wicket Stadium Century Match",
'Food': "Pizza Burger Pasta Noodles Biryani Curry Dessert Chocolate Sweet Spicy",
'Travel': "Beach Mountain Adventure RoadTrip Flight Hotel Explore Journey Nature"
}
wc = WordCloud(width=1000, height=600, background_color='white', colormap='viridis').generate(texts[topic])
fig = px.imshow(wc.to_array())
fig.update_layout(title=f"WordCloud: {topic}", coloraxis_showscale=False, margin=dict(t=50))
return fig
app.run(debug=True)
Hinglish Tip: Dropdown change → live update — students ko magic lagega!
Common Mistakes to Avoid
| Mistake | Fix |
|---|---|
| Words overlap | Use |
| Mask not working | Mask must be white background, black shape (PIL) |
| Colors not visible | Use |
| Can't save image | Install |
| Too small in report | Use |