mcpField
W
word-cloud-generator

word-cloud-generator

github.com/dkyazzentwatwaデータ・データベース12461 回インストール29 週間前に更新
リポジトリ

word-cloud-generator について

word-cloud-generatorは、テキスト、ファイル、または単語頻度辞書からワードクラウドを作成するPythonツールです。形状、色、フォントを設定し、PNGまたはSVGで出力できます。

主な機能

  1. 01テキスト、ファイル、頻度辞書を入力
  2. 02矩形、円形、カスタムマスクを使用
  3. 03カラーマップまたは独自の色を選択
  4. 04システムフォントまたは独自フォントを指定
  5. 05組み込みまたは独自のストップワードで除外
  6. 06PNGまたはSVGで出力

活用シーン

  1. 01記事やテキストファイルからワードクラウドを作成
  2. 02頻度データを使って単語を可視化
  3. 03ロゴや画像の形に合わせたワードクラウドを作成
  4. 04指定した色とフォントでブランド用の画像を作成

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/dkyazzentwatwa/chatgpt-skills --skill word-cloud-generator

インストール後、Claude Code で/word-cloud-generatorを入力して読み込まれたか確認します。

同梱ファイルscripts/requirements.txtscripts/wordcloud_gen.py

詳細

ワードクラウドジェネレーター

テキスト、ファイル、または単語頻度辞書から、見栄えのよいワードクラウドを作成します。形状、色、フォントをカスタマイズし、複数の形式でエクスポートできます。

クイックスタート

from scripts.wordcloud_gen import WordCloudGenerator

# From text
wc = WordCloudGenerator("Python is amazing. Python is powerful. Code is fun.")
wc.generate().save("cloud.png")

# From file
wc = WordCloudGenerator.from_file("article.txt")
wc.colors("plasma").max_words(100).generate().save("cloud.png")

# From frequency dict
frequencies = {"python": 50, "code": 30, "data": 25, "analysis": 20}
wc = WordCloudGenerator(frequencies=frequencies)
wc.shape("circle").generate().save("cloud.png")

機能

  • 複数の入力ソース:生テキスト、テキストファイル、または単語頻度辞書
  • 形状オプション:長方形、円、またはカスタムマスク画像
  • カラースキーム:20 種類以上の matplotlib カラーマップ、またはカスタムカラーリスト
  • フォントの選択:システムフォントまたはカスタムフォントファイルを使用
  • ストップワードのフィルタリング:組み込みの英語ストップワードとカスタム項目の追加
  • エクスポート形式:PNG、SVG

API リファレンス

初期化
# From text string
wc = WordCloudGenerator("Your text here")

# From frequency dictionary
wc = WordCloudGenerator(frequencies={"word": count, ...})

# From file
wc = WordCloudGenerator.from_file("path/to/file.txt")
設定メソッド

すべてのメソッドは、メソッドチェーン用に self を返します。

# Shape options
wc.shape("rectangle")           # Default rectangle
wc.shape("circle")              # Circular cloud
wc.shape(mask="logo.png")       # Custom shape from image

# Color schemes (matplotlib colormaps)
wc.colors("viridis")            # Default
wc.colors("plasma")             # Purple-yellow gradient
wc.colors("coolwarm")           # Blue-red diverging
wc.colors("Set2")               # Categorical colors
wc.colors(custom=["#FF0000", "#00FF00", "#0000FF"])  # Custom colors

# Font settings
wc.font("/path/to/font.ttf")    # Custom font file

# Stopwords
wc.stopwords(use_default=True)                    # Use built-in stopwords
wc.stopwords(words=["custom", "words"])           # Add custom stopwords
wc.stopwords(words=["the", "and"], use_default=False)  # Only custom

# Word limits
wc.max_words(200)               # Maximum words to display (default: 200)
wc.min_word_length(3)           # Minimum word length (default: 1)

# Size
wc.size(800, 400)               # Width x Height in pixels
生成とエクスポート
# Generate the word cloud
wc.generate()

# Save to file
wc.save("output.png")           # PNG format
wc.save("output.svg")           # SVG format (auto-detected)
wc.save("output.png", format="png")  # Explicit format

# Display (matplotlib)
wc.show()

# Get word frequencies
freqs = wc.get_frequencies()    # Returns dict of word: frequency

カラースキーム

よく使われるカラーマップ
名前説明
viridis青緑黄色(デフォルト)
plasma紫橙黄色
inferno黒赤黄色
magma黒紫白
cividis青黄色(色覚多様性に配慮)
coolwarm青白赤
RdYlBu赤黄色青
Spectral虹色スペクトル
Set1鮮やかなカテゴリカラー
Set2落ち着いたカテゴリカラー
Pastel1柔らかなカテゴリカラー
Dark2暗めのカテゴリカラー
カスタムカラー
# Hex colors
wc.colors(custom=["#1a1a2e", "#16213e", "#0f3460", "#e94560"])

# Named colors
wc.colors(custom=["navy", "royalblue", "cornflowerblue", "lightsteelblue"])

形状マスク

組み込みの形状
wc.shape("rectangle")  # Default
wc.shape("circle")     # Circular
wc.shape("square")     # Square
カスタムマスク画像

白い領域が単語で塗りつぶされる画像を使用します。

# Use logo or shape image as mask
wc.shape(mask="company_logo.png")
wc.shape(mask="heart.png")
wc.shape(mask="map_outline.png")

マスク画像の要件:

  • 白(#FFFFFF)の領域が単語で塗りつぶされます
  • 黒や暗い色の領域は空白になります
  • コントラストの高い画像が最適です
  • 推奨サイズ:800x800 ピクセル以上

CLI の使用方法

# Basic usage
python wordcloud_gen.py --text "Your text here" --output cloud.png

# From file
python wordcloud_gen.py --file article.txt --output cloud.png

# With options
python wordcloud_gen.py --file data.txt \
    --shape circle \
    --colors plasma \
    --max-words 150 \
    --output cloud.png

# Custom mask
python wordcloud_gen.py --file speech.txt \
    --mask logo.png \
    --colors Set2 \
    --output branded_cloud.png

# SVG output
python wordcloud_gen.py --text "Hello World" --output cloud.svg
CLI 引数
引数説明デフォルト
--text入力テキスト文字列-
--file入力テキストファイルのパス-
--output出力ファイルのパスwordcloud.png
--shape形状:rectangle、circle、squarerectangle
--maskカスタムマスク画像のパス-
--colorsカラーマップ名viridis
--max-words単語の最大数200
--min-length単語の最小長1
--width画像の幅800
--height画像の高さ400
--fontカスタムフォントファイル-
--no-stopwordsストップワードのフィルタリングを無効化False
--stopwords追加するストップワード(カンマ区切り)-

例

基本的なワードクラウド
text = """
Python is a versatile programming language. Python is used for web development,
data science, machine learning, and automation. Python's simplicity makes it
perfect for beginners while its power serves experts.
"""

wc = WordCloudGenerator(text)
wc.colors("plasma").generate().save("python_cloud.png")
頻度に基づくワードクラウド
# Word frequencies from analysis
tech_terms = {
    "Python": 100,
    "JavaScript": 85,
    "Machine Learning": 70,
    "API": 65,
    "Database": 60,
    "Cloud": 55,
    "DevOps": 45,
    "Kubernetes": 40,
    "Docker": 38,
    "React": 35
}

wc = WordCloudGenerator(frequencies=tech_terms)
wc.shape("circle").colors("Set2").generate().save("tech_cloud.png")
ブランドワードクラウド
# Use company logo as mask
wc = WordCloudGenerator.from_file("company_values.txt")
wc.shape(mask="logo_white_bg.png")
wc.colors(custom=["#003366", "#0066cc", "#3399ff"])
wc.font("/fonts/OpenSans-Bold.ttf")
wc.generate().save("branded_cloud.png")
記事の分析
# Analyze article removing common words
wc = WordCloudGenerator.from_file("news_article.txt")
wc.stopwords(words=["said", "according", "reported"])  # Add domain stopwords
wc.min_word_length(4)
wc.max_words(100)
wc.colors("RdYlBu")
wc.generate().save("article_themes.png")

# Get top words
top_words = wc.get_frequencies()
for word, freq in list(top_words.items())[:10]:
    print(f"{word}: {freq}")

依存関係

wordcloud>=1.9.0
matplotlib>=3.7.0
Pillow>=10.0.0
numpy>=1.24.0

制限事項

  • SVG エクスポートでは PNG から変換します(ネイティブのベクター形式ではありません)
  • 非常に大きなテキストは処理に時間がかかる場合があります
  • カスタムフォントは TrueType(.ttf)または OpenType(.otf)形式である必要があります
  • マスク画像には、シンプルでコントラストの高い形状が最適です

コメント