Plots¶
Functions used to visualize the patch/embeddings/results.
- plot_embeddings(input_dictionary, embedding_key, annotation_keys, sup_title=None, n_col=3, cmap='inferno')[source]¶
Takes a dictionary with embeddings and multiple annotations and make a multi-panel figure with each panel showing one annotation.
- Parameters
input_dictionary (
dict
) – dictionary with input dataembedding_key (
str
) – str corresponding to the embeddings in input_dictionary. Embedding have shape (n_sample, latent_dim). Only the first two latent dimensions will be used for plotting.annotation_keys (
List
[str
]) – List[str] corresponding to annotations in input_dictionary.sup_title (
Optional
[str
]) – the title (if any) for the figuren_col (
int
) – how many columns to have in the multi-panel figurecmap (
Colormap
) – the color map to use for the continuous variable. The categorical variable will have a different cmap.
- Returns
fig – multi-panel figure with the embeddings
- Return type
Figure
- pad_and_crop_and_stack(x, pad_value=0.0)[source]¶
Takes a list of tensor and returns a single batched_tensor. It is useful for visualization.
- Parameters
x (
List
[Tensor
]) – a list of tensor with the same channel dimension but possibly different width and heigthpad_value (
float
) – float, the value used in padding the images. Defaults to padding with black colors
- Returns
tensor – A single batch tensor of shape \((B, c, \text{width}_\text{max}, \text{height}_\text{max})\)
- Return type
Tensor
- show_batch(tensor, cmap=None, n_col=4, n_padding=10, title=None, pad_value=1, normalize=True, normalize_range=None, figsize=None)[source]¶
Visualize a torch tensor of shape: \((*, \text{ch}, \text{width}, \text{height})\). It works for any number of leading dimensions.
- Parameters
tensor (
Tensor
) – the torch.Tensor to plotcmap (
Optional
[str
]) – the color map to use. If None, it defaults to ‘gray’ for 1 channel images, RGB for 3 channels images and ‘tab20’ for images with more that 3 channels.n_col (
int
) – int, number of columns in the image gridn_padding (
int
) – int, padding between images in the gridtitle (
Optional
[str
]) – str, the tile on the imagepad_value (
int
) – float, pad_valuenormalize (
bool
) – bool, if tru normalize the tensor in normalize_rangenormalize_range (
Optional
[Tuple
[float
,float
]]) – tuple, if not specified it is set to (min_image, max_image)figsize (
Optional
[Tuple
[float
,float
]]) – size of the figure
- Return type
Figure
- show_raw_all_channels(data, n_col=4, cmap=None, figsize=None, titles=None, sup_title=None, show_colorbar=None, legend_colorbar=None, show_axis=True)[source]¶
Visualize a torch tensor of shape: \((*, \text{ch}, \text{width}, \text{height})\) or a list of tensors of shape \((\text{ch}, \text{width}, \text{height})\).
- Parameters
data (
Union
[Tensor
,List
[Tensor
]]) – A torch.tensor of shape \((*, \text{ch}, \text{width}, \text{height})\) or a list of tensor of shape \((\text{ch}, \text{width}, \text{height})\)n_col (
int
) – number of columns to plot the datacmap (
Optional
[str
]) – the matplotlib color map to use. Defaults to RBG (if data has 3 channels) or ‘tab20’ otherwise.figsize (
Optional
[Tuple
[float
,float
]]) – Optional, the tuple with the width and height of the rendered figuretitles (
Optional
[List
[str
]]) – list with the titles for each panelsup_title (
Optional
[str
]) – the title for the entire imageshow_colorbar (
Optional
[bool
]) – bool, if yes show the color barlegend_colorbar (
Optional
[List
[str
]]) – legend for the colorbarshow_axis (
bool
) – If True (default) show the axis
- Returns
fig – A figure with * panels each panel is a rendering of a tensors of shape \((\text{ch}, \text{width}, \text{height})\)
- Return type
Figure
- show_raw_one_channel(data, n_col=4, cmap=None, in_range='image', scale_each=True, figsize=None, titles=None, sup_title=None, show_axis=True)[source]¶
Visualize a torch tensor of shape \((*, \text{width}, \text{height})\). or a list of tensor of shape \((\text{width}, \text{height})\). Each leading dimension is shown separately.
- Parameters
data (
Union
[Tensor
,List
[Tensor
]]) – A torch.tensor of shape \((*, \text{width}, \text{height})\) or list of tensor of shape \((\text{width}, \text{height})\).n_col (
int
) – number of columns to plot the datacmap (
Optional
[str
]) – the matplotlib color map to use. If None use ‘gray’ colormap.in_range (
Union
[str
,Tuple
[float
,float
]]) – Either a tuple specifying a a min and max value (for clamping) or a string ‘image’. If ‘image’ the min and max value are computed form the image itself. Value are clamped in_range and then transformed to range (0.0, 1.0) for visualization.scale_each (
bool
) – bool if true each leading dimension is scaled by itself. It has effect only if in_range = ‘image’figsize (
Optional
[Tuple
[float
,float
]]) – Optional, the tuple with the width and height of the rendered figuretitles (
Optional
[List
[str
]]) – list with the titles for each small imagesup_title (
Optional
[str
]) – str, the title for the entire imageshow_axis (
bool
) – If True (defaults) show the axis.
- Returns
fig – A figure with (*) panels. Each panel is a rendering of a tensor of shape \((\text{width}, \text{height})\)
- Return type
Figure
- plot_cdf_pdf(pdf_y=None, cdf_y=None, x_label=None, sup_title=None)[source]¶
Plot the Probability Density Function (pdf) and Cumulative Density Function (cdf).
- Parameters
pdf_y (
Union
[ndarray
,Tensor
,None
]) – array like datacdf_y (
Union
[ndarray
,Tensor
,None
]) – Optional. The cdf to plot. If not present it can be computed internally from pdf_yx_label (
Optional
[str
]) – the label of the x-axissup_title (
Optional
[str
]) – the title for both panels
- Returns
fig – A two panel figure with the pdf and cdf.
- Return type
Figure
- plot_clusters_annotations(input_dictionary, cluster_key, annotation_keys, titles=None, sup_title=None, n_col=3, figsize=None)[source]¶
ADD DOC STRING
- Return type
Figure
- plot_multiple_barplots(data, x, ys, n_col=4, figsize=None, y_labels=None, x_labels_rotation=90, x_labels=None, titles=None, y_lims=None, **kargs)[source]¶
IMPROVE DOCSTRING
Takes a dataframe and make multiple bar plots leveraging seaborn.barplot(y=y, x=x, data=data)
- Parameters
data (
DataFrame
) – a dataframe with the data to plotx (
str
) – names of (independent) variables in datays (
List
[str
]) – names of (dependent) variables in datan_col (
int
) – number of columns panels in the figurefigsize (
Optional
[Tuple
[float
,float
]]) – size of the output figurex_labels (
Optional
[List
[str
]]) – label for the x-axisy_labels (
Optional
[List
[str
]]) – labels for the y-axisx_labels_rotation (
int
) – rotation in degree of the x_labels (default 90)titles (
Optional
[List
[str
]]) – titles for each panely_lims (
Optional
[Tuple
[float
,float
]]) – set limits for the y coordinate for all the panelskargs – any argument passed to seaborn.barplot such as hue,
- Returns
fig – Figure with XXX panels
- Return type
Figure
- plot_knn_examples(input_dict, embedding_key, image_key, n_neighbors=3, examples=6, metric='euclidean', cmap=matplotlib.pyplot.cm.viridis, figsize=None, plot_histogram=False, max_distance=None, **kargs)[source]¶
NEED TO BE REARRANGED b/c INTERFACE HAS CHANGED
- Parameters
input_dict (
dict
) – dictionary with the images of the crops and their embeddingsembedding_key (
str
) – str, key corresponding to the embeddings in the input_dict (or distance_matrix if :attr:’metric’ == ‘precomputed’)image_key (
str
) – str, key corresponding to the images in the input_dictn_neighbors (
int
) – int, how many nearest neighbour to plotexamples (
Union
[int
,List
[int
]]) – either a list of int with the index of the example whose nearest neighbour to show or an int. If an int, the example will be selected at random.metric (
str
) – which metric to use. Either “euclidean”, “cosine” or “contrastive”cmap (
ListedColormap
) – the colormap to use for plottingfigsize (
Optional
[Tuple
[int
,int
]]) – size of the image. Default to Noneplot_histogram (
bool
) – if true, the histogram of distances is shownmax_distance (
Optional
[float
]) – float, if given distances larger than this value will be excluded from the histogram.kargs – additional parameter which will be passed to matplotlib.hist() function. For example ‘bins=50’, ‘density=True’.
- Returns
a matplotlib figure with example fo knn neighbours.