jina.types.arrays.mixins.plot module

class jina.types.arrays.mixins.plot.PlotMixin[source]

Bases: object

Helper functions for plotting the arrays.

plot_embeddings(title='MyDocumentArray', path=None, image_sprites=False, min_image_size=16, channel_axis=- 1, start_server=True, port=None)[source]

Interactively visualize embeddings using the Embedding Projector.

Parameters
  • title (str) – the title of this visualization. If you want to compare multiple embeddings at the same time, make sure to give different names each time and set path to the same value.

  • port (Optional[int]) – if set, run the embedding-projector frontend at given port. Otherwise a random port is used.

  • image_sprites (bool) – if set, visualize the dots using uri and blob.

  • path (Optional[str]) – if set, then append the visualization to an existing folder, where you can compare multiple embeddings at the same time. Make sure to use a different title each time .

  • min_image_size (int) – only used when image_sprites=True. the minimum size of the image

  • channel_axis (int) – only used when image_sprites=True. the axis id of the color channel, -1 indicates the color channel info at the last axis

  • start_server (bool) – if set, start a HTTP server and open the frontend directly. Otherwise, you need to rely on return path and serve by yourself.

Return type

str

Returns

the path to the embeddings visualization info.

plot_embeddings_legacy(output=None, title=None, colored_attr=None, colormap='rainbow', method='pca', show_axis=False, **kwargs)[source]

Plot embeddings in a 2D projection with the PCA algorithm. This function requires matplotlib installed.

If tag_name is provided the plot uses a distinct color for each unique tag value in the documents of the DocumentArray.

Parameters
  • output (Optional[str]) – Optional path to store the visualization. If not given, show in UI

  • title (Optional[str]) – Optional title of the plot. When not given, the default title is used.

  • colored_attr (Optional[str]) – Optional str that specifies attribute used to color the plot, it supports dunder expression such as tags__label, matches__0__id.

  • colormap (str) – the colormap string supported by matplotlib.

  • method (str) – the visualization method, available pca, tsne. pca is fast but may not well represent nonlinear relationship of high-dimensional data. tsne requires scikit-learn to be installed and is much slower.

  • show_axis (bool) – If set, axis and bounding box of the plot will be printed.

  • kwargs – extra kwargs pass to matplotlib.plot

plot_image_sprites(output=None, canvas_size=512, min_size=16, channel_axis=- 1)[source]

Generate a sprite image for all image blobs in this DocumentArray-like object.

An image sprite is a collection of images put into a single image. It is always square-sized. Each sub-image is also square-sized and equally-sized.

Parameters
  • output (Optional[str]) – Optional path to store the visualization. If not given, show in UI

  • canvas_size (int) – the size of the canvas

  • min_size (int) – the minimum size of the image

  • channel_axis (int) – the axis id of the color channel, -1 indicates the color channel info at the last axis

Return type

None