tag_word_cloud

Functions

create_wordcloud(word_dict[, mask_path, ...])

Takes a word dict and returns a generated word cloud object

load_and_resize_mask(mask_path[, width, height])

Load a mask image and resize it according to given dimensions.

summary_to_dict(summary[, transform, adjustment])

Converts a HedTagSummary json dict into the word cloud input format

word_cloud_to_svg(wc)

Takes word cloud and returns it as an SVG string.

create_wordcloud(word_dict, mask_path=None, background_color=None, width=400, height=None, **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:

word_cloud(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

summary_to_dict(summary, transform=<ufunc 'log10'>, adjustment=5)[source]

Converts a HedTagSummary json dict into the word cloud input format

Parameters:
  • summary (dict) – The summary from a summarize hed tags op

  • transform (func) – The function to transform the number of found tags Default log10

  • adjustment (int) – Value added after transform.

Returns:

a dict of the words and their occurrence count

Return type:

word_dict(dict)

Raises:

KeyError – A malformed dictionary was passed

word_cloud_to_svg(wc)[source]

Takes word cloud and returns it as an SVG string.

Parameters:

wc (WordCloud) – the word cloud object

Returns:

The svg for the word cloud

Return type:

svg_string(str)