wordcloud

repository·main·Indexed 27 days ago

https://github.com/amueller/word_cloud

A Python library used to generate word cloud visualizations from text data or frequency distributions. It features the WordCloud class for core generation, ImageColorGenerator for image-based color mapping, and a command-line tool (wordcloud_cli). Key capabilities include masking, custom TrueType fonts, SVG export, and support for stopwords and collocations.

Tokens
2.6K
Snippets
4
Records
24
Agent score
89%

What's inside wordcloud

  1. Release the wordcloud package to PyPI

    main

    Follow these steps to trigger a new release of wordcloud. Ensure all CI tests (AppVeyor, CircleCI, Travis CI) are passing before starting.

    1. Identify version: List existing tags to choose the next version: git tag -l | sort -V. Note: Tags must match the regex ^[0-9]+(\.[0-9]+)*(\.(post[0-9]+))?$.
    2. Update Changelog: In doc/changelog.rst, rename the Next Release header to WordCloud X.Y.Z and commit the change.
    3. Tag and Push: Create a signed tag and push it to origin. Pushing the tag triggers the CI builds that automatically upload wheels and source distributions to PyPI.
    4. Verify: Check CI status and ensure distributions appear on PyPI.
    5. Test Installation: Create a clean environment to verify the installation works.
    6. Finalize: Restore the Next Release section in doc/changelog.rst and push the master branch.
    # 1. Update changelog
    $ git add doc/changelog.rst
    $ git commit -m "WordCloud ${release}"
    
    # 2. Tag the release (recommended to use GPG)
    $ git tag --sign -m "WordCloud ${release}" ${release} master
    
    # 3. Publish the tag to trigger CI/PyPI upload
    $ git push origin ${release}
    
    # 4. Test the installation in a clean environment
    $ mkvirtualenv wordcloud-${release}-install-test && \
      pip install wordcloud && \
      python -c "import wordcloud;print(wordcloud.__version__)"
    
    # 5. Cleanup
    $ deactivate  && \
      rm -rf dist/* && \
      rmvirtualenv wordcloud-${release}-install-test
    
    # 6. Restore changelog and push master
    $ git push origin master
  2. Configure PyPI credentials in ~/.pypirc

    main

    To upload packages to PyPI, you must create a ~/.pypirc file containing your login credentials. This file should include configuration for both the production pypi index and the pypitest repository.

    [distutils]
    index-servers =
      pypi
      pypitest
    
    [pypi]
    username=<your-username>
    password=<your-password>
    
    [pypitest]
    repository=https://test.pypi.org/legacy/
    username=<your-username>
    password=<your-password>
  3. Install wordcloud via pip or conda

    main

    You can install the wordcloud package using pip or via the conda-forge channel in conda.

    Note that wordcloud depends on numpy, pillow, and matplotlib. If no wheels are available for your Python version, a C compiler will be required for installation.

  4. Use color functions for custom coloring

    main

    The library provides several functions to control word coloring:

    • random_color_func: Generates random colors for words.
    • colormap_color_func: Uses a colormap to assign colors.
    • get_single_color_func: Returns a function that provides a single color for all words.
  5. Use wordcloud_cli for command-line generation

    main

    The wordcloud_cli tool allows you to generate word clouds directly from the terminal. You can provide text via a file using the --text flag and specify the output image filename with --imagefile.

    To process PDF files, you can pipe the output of pdftotext into wordcloud_cli.

  6. Use custom color functions

    main

    You can provide a custom color_func to the WordCloud constructor or the recolor method. The function must accept the following parameters: word, font_size, position, orientation, font_path, and random_state.

    Common patterns:

    • Single color: color_func=lambda *args, **kwargs: "white" or color_func=lambda *args, **kwargs: (255, 0, 0) for red.
    • Matplotlib colormaps: Use the colormap_color_func class or pass a colormap name to the colormap parameter.
    • Single hue/saturation: Use get_single_color_func(color) to create a function that picks random values based on a base color.