Python語雲図WordCloud

1322 ワード

WordCloud公式サイト
公式の最も簡単な例:
from os import path
from wordcloud import WordCloud

d = path.dirname(__file__)

# Read the whole text.
text = open(path.join(d, 'constitution.txt')).read()

# Generate a word cloud image
wordcloud = WordCloud().generate(text)

# Display the generated image:
# the matplotlib way:
import matplotlib.pyplot as plt
plt.imshow(wordcloud, interpolation='bilinear')
plt.axis("off")

# lower max_font_size
wordcloud = WordCloud(max_font_size=40).generate(text)
plt.figure()
plt.imshow(wordcloud, interpolation="bilinear")
plt.axis("off")
plt.show()

# The pil way (if you don't have matplotlib)
# image = wordcloud.to_image()
# image.show()

公式のすべての例を表示
必要:
  • 文字は色を統一します.
  • 透明な背景.
  • は、指定されたスタイルで表示されます.

  • すべての色が#FFF0D0であることが要求され、オンラインツールを使用してRGBをhsl形式に変換する:hsl(40.9,100%,90.8%).WordCloudAPI hsl値が浮動小数点数の場合に異常であるため、整数hsl(41,100%,91%)に変更された.
    文字の色を統一WordCloud(mode='RGBA', colormap='pink') modeRGBAに設定されている場合、colormap色の値を使用して、パラメータの値はドキュメントまたはエラーメッセージから知ることができます.
    背景の透明性WordCloud(background_color=None)
    参照先:
    Using custom colors
    Python語雲wordcloud 15分入門と進級