tag_word_cloud¶
Utilities for creating a word cloud.
Functions
|
Takes a word dict and returns a generated word cloud object. |
|
Load a mask image and resize it according to given dimensions. |
Return a WordCould as an SVG string. |
- create_wordcloud(word_dict, mask_path=None, background_color=None, width=400, height=300, **kwargs)[source]¶
Takes a word dict and returns a generated word cloud object.
- Parameters:
word_dict (dict) – words and their frequencies
mask_path (str or None) – The path of the mask file
background_color (str or None) – If None, transparent background.
width (int) – width in pixels.
height (int) – height in pixels.
kwargs (kwargs) – Any other parameters WordCloud accepts, overrides default values where relevant.
- Returns:
The generated cloud. (Use .to_file to save it out as an image.)
- Return type:
WordCloud
- Raises:
ValueError – An empty dictionary was passed
- load_and_resize_mask(mask_path, width=None, height=None)[source]¶
Load a mask image and resize it according to given dimensions.
The image is resized maintaining aspect ratio if only width or height is provided.
Returns None if no mask_path.
- Parameters:
mask_path (str) – The path to the mask image file.
width (int, optional) – The desired width of the resized image. If only width is provided, the image is scaled to maintain its original aspect ratio. Defaults to None.
height (int, optional) – The desired height of the resized image. If only height is provided, the image is scaled to maintain its original aspect ratio. Defaults to None.
- Returns:
The loaded and processed mask image as a numpy array with binary values (0 or 255).
- Return type:
numpy.ndarray