mpl_interactions.generic module#
Functions that will be useful irrespective of backend.
- heatmap_slicer(X, Y, heatmaps, slices='horizontal', heatmap_names=None, linecolor='k', labels=('X', 'Y'), interaction_type='move', fig=None, figsize=(18, 9), **pcolormesh_kwargs)[source]#
Compare horizontal and/or vertical slices across multiple arrays.
- Parameters:
- X,Y1D array
The values for the x and y axes.
- heatmapsarray_like
must be 2-D or 3-D. If 3-D the last two axes should be (X,Y)
- slices{‘horizontal’, ‘vertical’, ‘both’}
Direction to draw slice on heatmap. both will draw horizontal and vertical traces on the same plot, while both_separate will make a line plot for each.
- heatmap_names(String, String, …)
An iterable with the names of the heatmaps. If provided it must have as many names as there are heatmaps
- figsizetuple of number, default: (18, 9)
The size of the created figure. Ignored if fig is not None.
- linecolorcolorlike, default: ‘k’
The color of the cursor showing the slices. Must be a valid Matplotlib linecolor.
- labels(string, string), default: (“X”, “Y”)
The labels for the x and y axes.
- interaction_typestr
Update on mouse movement or mouse click. Options are {‘move’,’click’}
- figmatplotlib figure, optional
The figure to use for the heatmap_slicer. Useful when embedding into a gui. If you are embedding into a gui make sure you set up the gui canvas first and then pass the figure to this function
- **pcolormesh_kwargs
kwargs passed to
ax.pcolormesh
.
- Returns:
- figmatplotlib.Figure.figure
- axtuple of matplotlib.axes.Axes
- hyperslicer(arr, alpha=None, vmin=None, vmax=None, vmin_vmax=None, autoscale_cmap=True, ax=None, slider_formats=None, title=None, force_ipywidgets=False, play_buttons=False, is_color_image=False, controls=None, display_controls=True, **kwargs)[source]#
View slices from a hyperstack of images selected by sliders.
Also accepts Xarray.DataArrays in which case the axes names and coordinates will be inferred from the xarray dims and coords.
- Parameters:
- arrarraylike or xarray
Hyperstack of images. The last 2 or 3 dimensions will be treated as individiual images. If an xarray.DataArray then the dimensions will be automatically inferred.
- alphafloat, Callable or widget shorthand, indexed controls, optional
The alpha of the image. If a callable then it will receive parameters be autoupdated. Can also be given a widget shorthand to automatically generate a slider (e.g.
alpha = (0, 1, 10)
).- vmin, vmaxfloat, callable, shorthand for slider or indexed controls, optional
The vmin, vmax values for the colormap. Can accept a float for a fixed value, or any slider shorthand to control with a slider, or an indexed controls object to use an existing slider, or an arbitrary function of the other parameters.
- vmin_vmaxtuple of float
Used to generate a range slider for vmin and vmax. Should be given in range slider notation:
("r", 0, 1)
.- autoscale_cmapbool
If True rescale the colormap for every function update. Will not update if vmin and vmax are provided or if the returned image is RGB(A) like. forwarded to matplotlib
- axmatplotlib axis, optional
if None a new figure and axis will be created
- slider_formatsNone, string, or dict
If None a default value of decimal points will be used. Uses the new {} style formatting
- titleNone or string
If a string then you can have it update automatically using string formatting of the names of the parameters. i.e. to include the current value of tau: title=’the value of tau is: {tau:.2f}’
- force_ipywidgetsboolean
If True ipywidgets will always be used, even if not using the ipympl backend. If False the function will try to detect if it is ok to use ipywidgets If ipywidgets are not used the function will fall back on matplotlib widgets
- play_buttonsbool or str or dict, optional
Whether to attach an ipywidgets.Play widget to any sliders that get created. If a boolean it will apply to all kwargs, if a dictionary you choose which sliders you want to attach play buttons too. - None: no sliders - True: sliders on the lft - False: no sliders - ‘left’: sliders on the left - ‘right’: sliders on the right
- is_color_imageboolean
If True, will treat the last 3 dimensions as comprising a color images and will only set up sliders for the first arr.ndim - 3 dimensions.
- controlsmpl_interactions.controller.Controls
An existing controls object if you want to tie multiple plot elements to the same set of controls
- display_controlsboolean
Whether the controls should display on creation. Ignored if controls is specified.
- **kwargs
names
can be used to set the axes names,axes
can be used to set the displayed values of multiple sliders, andaxis0
,axis1
etc can be used with widget shorthand to set the displayed values of the sliders. All valid imshow kwargs are passed through toimshow
.
- Returns:
- controls
- class image_segmenter(img, nclasses=1, mask=None, mask_colors=None, mask_alpha=0.75, lineprops=None, props=None, lasso_mousebutton='left', pan_mousebutton='middle', ax=None, figsize=(10, 10), **kwargs)[source]#
Bases:
object
Manually segment an image with the lasso selector.
- mask#
See Image Segmentation.
- class panhandler(fig, button=3)[source]#
Bases:
object
Enable panning a plot with any mouse button.
handler = panhandler(my_figure) # Let it be disabled and garbage collected handler = None
- Parameters:
- buttonint
Determines which button will be used (default right click). Left: 1 Middle: 2 Right: 3
- disable()[source]#
Disable the panhandler.
- Raises:
- RuntimeError
If the panhandler is already disabled.
- enable()[source]#
Enable the panhandler.
It should not be necessary to call this function unless it’s used after a call to
panhandler.disable()
.- Raises:
- RuntimeError
If the panhandler is already enabled.