Plotting

The plotting module sets up the plots, the legend and all the buttons and widgets to interact with the data.

More precisely, it is responsible for:

  • Creating the main Bokeh figure and rendering the 2D or 3D data embedding from an AnnData object.

  • Implementing the complex client-side JavaScript callbacks that enable real-time 3D rotation (yaw, pitch, roll) and depth perception.

  • Setting up standard Bokeh tools like HoverTool, LassoSelectTool, and sliders for user interaction.

  • Coloring data points on the main scatter plot based on the values of one or more user-selected features.

  • Generating violin plots and heatmaps, to visualize the distribution of feature values across different user-defined subsets or existing categorical labels.

  • Managing the data sources and handling updates based on user interactions.

color_by_feature_value(points_bokeh_plot, violins_bokeh_plot, heat_map, adata, select_color_by, hidden_text_label_column, resize_width_input, hidden_legend_width, hidden_checkbox_A, hidden_checkbox_B, resize_w_input, resize_h_input, bt_slider_range, select_field)[source]

Set up widgets and callbacks for coloring points by feature value. Update the plot coloring and refresh violin and heatmap plots based on user’s selected features and groups.

Parameters:
Returns:

Tuple containing the Bokeh widgets created by this function
  • offset_text_feature_color (bokeh.models.TextInput): Text input for entering feature names to color samples in the scatter plot.

  • offset_label (bokeh.models.TextInput): A hidden text input that stores the group labels for generating violin/heatmap plots.

plot_var(adata, violins_bokeh_plot, heat_map, resize_w, resize_h, hidden_checkbox_A, hidden_checkbox_B, features, selected_labels=None)[source]

Create or update violin plots and heatmaps showing feature(s) distributions for subsets of observations (e.g., subsets A, B, rest, or user-defined groups).

Parameters:
Returns:

None

check_obs_field(udict, field)[source]

Check if a categorical field has a manageable number of unique values.

Parameters:
  • udict (dict) – Dictionary mapping .obs keys to their number of unique values.

  • field (str) – Field to check, should be a key of udict.

Returns:

True if the number of unique values is less than or equal to MAX_UNIQUE_VALUES, False otherwise.

main_figure(adata, embedding_key, width=900, height=600, title='')[source]

Create the main interactive figure and all associated widgets.

Parameters:
  • adata (anndata.AnnData) – Annotated data matrix of shape n_obs x n_vars.

  • embedding_key (str) – The string key from adata.obsm specifying which embedding to plot.

  • width (int) – Width of the main figure in pixels.

  • height (int) – Height of the main figure in pixels.

  • title (str) – Title for the main figure.

Returns:

Tuple containing all the created Bokeh components

setup_legend(pb_plot, obs_string, obs_string_many, obs_numerical, source_rotmatrix_etc, resize_width_input, bt_slider_range, unique_dict)[source]

Set up interactive legend and color mapping for a scatter plot. Creates Bokeh widgets and callbacks that control coloring of points by categorical or numerical observation fields, and dynamically builds legends or color bars depending on the field type.

Parameters:
  • pb_plot – The main scatter plot figure.

  • obs_string – List of categorical .obs keys with <= 40 unique values.

  • obs_string_many – List of categorical .obs keys with > 40 unique values.

  • obs_numerical – List of numerical observation fields.

  • source_rotmatrix_etc – bokeh.models.ColumnDataSource Data source for computing points’ positions after rotations in the scatterplot.

  • resize_width_input – bokeh.models.TextInput Input for setting main plot’s width.

  • bt_slider_range – bokeh.models.RangeSlider Slider for filtering samples based on a selected feature’s value.

  • unique_dict – dict Dictionary mapping field names to lists of unique values.

Returns:

Tuple containing all the created Bokeh components
  • select_color_by (bokeh.models.Select): Dropdown menu for choosing a coloring field, its values will be added in the legend.

  • help_button (bokeh.models.HelpButton): A help tooltip for the select widget.

  • hidden_text_label_column (bokeh.models.TextInput): A hidden widget that triggers the color update via JavaScript.

  • hidden_legend_width (bokeh.models.TextInput): A hidden widget that stores the current width of the legend.

  • select_field (bokeh.models.Select): Dropdown menu in the legend for selecting a group from a field with many unique values.

  • label_signature (bokeh.models.MultiSelect): Widget for selecting groups in violin plots / heat map (initialized here).