Skip to content

Instantly share code, notes, and snippets.

@Hehehe421
Created October 10, 2023 00:16
Show Gist options
  • Save Hehehe421/034cff865bd408f22561c4c4b5b321d4 to your computer and use it in GitHub Desktop.
Save Hehehe421/034cff865bd408f22561c4c4b5b321d4 to your computer and use it in GitHub Desktop.
# Loop through each source and generate word clouds
for source, headlines in trending_news.items():
# Combine the headlines into a single string
headlines_text = ' '.join(headlines)
# Generate the word cloud
wordcloud = WordCloud(width=800, height=400, background_color='white').generate(headlines_text)
# Display the word cloud with the source name as the title
plt.figure(figsize=(12, 6))
plt.imshow(wordcloud, interpolation='bilinear')
plt.title(f'Trending News on {source}')
plt.axis("off")
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment