lazyslide.pl.WSIViewer#

class WSIViewer(wsi, in_bounds=True, img_bytes_limit=2000000000.0)#

Bases: object

The viewer for whole slide images.

Parameters:
wsiWSIData

The whole slide image data.

in_boundsbool, default: True

Whether to render the image in the bounds.

img_bytes_limitint, default: 2e9

The limit of the bytes to render image. The image size has a strong impact on the rendering time.

add_contours(key, label_by=None, color_by=None, palette=None, outline_color='#117554', hole_color='#4379F2', linewidth=1, outline_kwargs=None, hole_kwargs=None, legend_kws=None, legend=True, in_zoom=True, cache=True)#

Add contours to the plot.

Contours are the boundaries of the polygons. If you intend to plot filled polygons, use add_polygons instead.

Parameters:
keystr

The key of the polygon table.

label_bystr, optional

The column contains labels for the contours. The labels will be shown on top of the contours.

color_bystr, optional

The column contains colors or colors encoding (both categorical and continuous) for the contours. The color only affects the outline of the contours but not the holes.

palettedict, list, str, optional

The color palette for the colors. You can use a dict where the keys are the unique values in the color column and the values are the colors. If a list, the colors will be assigned to the unique values in the color column. If a color, all the contours will have the same color.

outline_colorcolor, default: “#117554”

The default color of the outline of the contours.

hole_colorcolor, default: “#4379F2”

The default color of the holes of the contours.

linewidthint, default: 1

The width of the contours.

outline_kwargsdict, optional

The keyword arguments for the outline of the contours.

hole_kwargsdict, optional

The keyword arguments for the holes of the contours.

legend_kwsdict, optional

The keyword arguments for the legend.

in_zoombool, default: True

Whether the contours are rendered in the zoom view.

legendbool, default: True

Whether to show the legend.

add_polygons(key, label_by=None, color_by=None, palette=None, alpha=0.9, color='#D3F527', linewidth=1, legend_kws=None, legend=True, in_zoom=True, cache=True, backend=None, **kwargs)#

Add filled polygons to the plot.

If you intend to plot only the outlines of the polygons, use add_contours instead.

Parameters:
keystr

The key of the polygon table.

label_bystr, optional

The column contains labels for the polygons. The labels will be shown on top of the polygons.

color_bystr, optional

The column contains colors or colors encoding (both categorical and continuous) for the polygons. The color will fill the polygons.

palettedict, list, str, optional

The color palette for the colors. You can use a dict where the keys are the unique values in the color column and the values are the colors. If a list, the colors will be assigned to the unique values in the color column. If a color, all the polygons will have the same color.

alphafloat, default: 0.3

The transparency of the polygons.

colorcolor, default: “#FFE31A”

The default color of the polygons.

linewidthint, default: 1

The width of the outline of the polygons.

legend_kwsdict, optional

The keyword arguments for the legend.

in_zoombool, default: True

Whether the polygons are rendered in the zoom view.

legendbool, default: True

Whether to show the legend.

cachebool, default: True

The plan will be cached if True.

backendstr, {‘matplotlib’, ‘datashader’}

The backend to use for plotting.

add_scalebar(label=None, length_fraction=None, width_fraction=None, location='lower right', pad=None, border_pad=None, sep=None, frameon=True, color='k', box_alpha=None, box_color='w', scale_loc='bottom', label_loc='top', font_properties=None, fixed_value=None, fixed_units=None, rotation=None, in_zoom=True, cache=True)#

Add a scale bar to the plot.

The scale bar is a matplotlib_scalebar.ScaleBar object.

Parameters:
labelstr, optional

The label of the scale bar.

length_fractionfloat, optional

The length of the scale bar as a fraction of the axes.

width_fractionfloat, optional

The width of the scale bar as a fraction of the axes.

location{‘upper right’, ‘upper left’, ‘lower left’, ‘lower right’, ‘right’, ‘center left’, ‘center right’, ‘lower center’, ‘upper center’, ‘center’, ‘best’}, optional

The location of the scale bar. Same as legend location in matplotlib.

padfloat, optional

The padding inside the scale bar.

border_padfloat, optional

The padding outside the scale bar.

sepfloat, optional

The separation between the scale bar and the label.

frameonbool, default: True

Whether to draw a box behind the scale bar.

colorstr, optional

The color of the scale bar.

box_alphafloat, optional

The alpha of the box.

box_colorstr, default: ‘w’

The color of the box.

scale_loc{‘top’, ‘bottom’, ‘left’, ‘right’}, optional

Location of the scale with respect to the scale bar.

label_loc{‘top’, ‘bottom’, ‘left’, ‘right’}, optional

The location of the label.

font_propertiesdict, optional

The font properties of the label.

fixed_valuefloat, optional

To fix the value of the scale bar.

fixed_unitsstr, optional

Units of the fixed_value.

rotation{‘horizontal’, ‘vertical’}, float, optional

The rotation of the scale bar.

add_tiles(key, feature_key=None, color_by=None, style='scatter', palette=None, cmap='coolwarm', norm=None, vmin=None, vmax=None, alpha=0.5, smooth=False, smooth_scale=2, rasterized=False, size=None, zoom_size=None, marker='o', gridcolor='k', linewidth=0.1, legend_kws=None, legend=True, in_zoom=True, cache=True)#

Add tiles to the plot.

Parameters:
keystr

The key of the tile table.

feature_keystr, optional

The key of the feature table to visualize.

color_bystr, optional

The column or feature to color the tiles by.

style{‘scatter’, ‘heatmap’}, default: ‘scatter’

The style to render the tiles.

palettedict, list, str, optional

The color palette for categorical coloring.

cmapstr, optional

The colormap for continuous coloring.

normmatplotlib.colors.Normalize, optional

The normalization for the colormap.

vmin, vmaxfloat, optional

The min and max values for the colormap.

alphafloat, default: 0.5

The transparency of the tiles.

smoothbool, default: False

Whether to apply smoothing to the heatmap.

smooth_scaleint, default: 2

The scale of the smoothing kernel.

rasterizedbool, default: False

Whether to rasterize the scatter plot.

sizefloat, optional

The size of the scatter points.

zoom_sizefloat, optional

The size of the scatter points in zoom view.

markerstr, default: ‘o’

The marker style for scatter.

gridcolorcolor, default: ‘k’

The color of the grid lines.

linewidthfloat, default: 0.1

The width of the grid lines.

legend_kwsdict, optional

The keyword arguments for the legend.

legendbool, default: True

Whether to show the legend.

in_zoombool, default: True

Whether to render in the zoom view.

cachebool, default: True

Whether to cache the render plan.

add_zoom(xmin=None, xmax=None, ymin=None, ymax=None, tissue_id=None, tissue_key='tissues', anchor=(1.2, 0), size=(1, 1), edgecolor='k', alpha=0.5, axis='on', xaxis='top', cache=True)#

Add a zoom window to the plot.

Parameters:
xmin, xmax, ymin, ymaxint, float, optional

The coordinates of the zoom window. You may also provide in (0-1) range to specify the fraction of the window.

tissue_idint, optional

The tissue id to zoom into.

tissue_keystr, optional

The key of the tissue table.

anchortuple, default: (1.2, 0)

The anchor point of the zoom window, relative to the main axes.

sizetuple, default: (1, 1)

The size of the zoom window, relative to the main axes.

set_viewport(x, y, w, h)#

Set the window to (x, y, w, h) at level 0