Widget in Jupyter NotebookConfiguration

Configuration

The Cosmograph widget builds upon the native Cosmograph library, inheriting most of its configuration parameters, which are mostly optional and can be modified in real-time. For basic usage examples, see Get started. For detailed insights about configuration parameters, refer to the documentation.

The data Parameter

The data parameter is a convenience feature that automatically assigns your DataFrame to either points or links, reducing boilerplate code. The default resolution behavior uses prioritize_points, but you can customize this with the data_resolution parameter (see Advanced Features).

Resolution rules (default: “prioritize points”):

  1. If data is provided and points is None:

    • data → points
  2. If data is provided and points already exists:

    • data → links (only if links is None)
  3. If both points and links are provided with data:

    • Raises ValueError

Examples:

# Simple: data → points
widget = cosmo(data=df, point_id_by='id')
 
# With links: data → links
widget = cosmo(points=nodes_df, data=edges_df, point_id_by='id', link_source_by='source', link_target_by='target')
 
# Error: both points and links specified
widget = cosmo(points=df1, links=df2, data=df3)  # ❌ Raises ValueError

Minimal Configuration for Points

To render a graph, the following minimal configuration is required:

ParameterDescription
pointsData in a pandas DataFrame format
point_id_byUnique identifier column for each point

Additional Points Configuration

ParameterDescription
point_index_byOrdinal index of each point (0 to n)
point_color_byColumn name for point colors
point_color_strategyStrategy for applying colors: None (auto), 'palette', 'interpolatePalette', 'map', 'degree', 'linkDirection', 'direct'
point_color_paletteArray of color strings for palette strategies
point_color_by_mapDictionary mapping values to colors (keys: string, values: str or [r, g, b, a])
point_colorDefault point color (when point_color_by not specified). Can be color string or [r, g, b, a] array
point_size_byColumn name for point sizes
point_size_strategyStrategy for sizing points: None (auto), 'direct', 'degree'
point_size_rangeRange for automatic point size scaling [min, max]
point_label_byColumn name for point labels
point_label_weight_byColumn name for point label weights
point_x_byColumn name for x-coordinate
point_y_byColumn name for y-coordinate
point_cluster_byColumn name for point clusters
point_cluster_strength_byColumn defining cluster attraction strength
cluster_positions_mapDictionary mapping cluster keys to [x, y] positions
point_include_columnsAdditional column names to include in point data
point_timeline_byColumn name for timeline/date data

To define links, the following fields are necessary:

ParameterDescription
linksData in a pandas DataFrame format
link_source_byColumn with unique identifier for source points
link_target_byColumn with unique identifier for target points (string or array for multi-target)
ParameterDescription
link_source_index_byIndex column of source point
link_target_index_byIndex column of target point
link_color_byColumn name for link colors
link_width_byColumn name for link widths
link_arrow_byColumn indicating links with arrows
link_strength_byColumn name for link strengths
link_strength_rangeRange for automatic link strength scaling [min, max]
link_include_columnsAdditional column names to include in link data
link_timeline_byColumn name for timeline/date data

Simulation Settings

ParameterDescription
disable_simulationPrevents simulation from running, renders graph only
simulation_decayHow quickly the simulation cools down
simulation_gravityCoefficient for gravity force
simulation_centerCenters the mass force coefficient
simulation_repulsionPoint repulsion between points
simulation_repulsion_thetaGranularity of Many-Body force (Barnes–Hut criterion when use_quadtree: True)
simulation_link_springSpring constant for links
simulation_link_distanceDefault distance for links
simulation_link_dist_random_variation_rangeRandom link distance range [min, max]
simulation_repulsion_from_mouseMouse position repulsion coefficient (right-click)
simulation_frictionSimulation friction
simulation_impulseCoefficient of simulation impulse (0 to 1)
simulation_clusterCluster coefficient

Graph Appearance

ParameterDescription
background_colorCanvas background color. Can be color string or [r, g, b, a] array
space_sizeSize of the simulation space
point_colorDefault point color (when point_color_by not specified). Can be color string or [r, g, b, a] array
point_greyout_opacityOpacity of unselected nodes during selection
point_sizeDefault size value for points (when point_size_by not provided)
point_size_scaleScale factor for point sizes
point_sampling_distanceDistance threshold for sampling points
hovered_point_cursorCursor type when hovering over a point
render_hovered_point_ringEnable ring around hovered points
hovered_point_ring_colorColor of hovered point ring. Can be color string or [r, g, b, a] array
focused_point_ring_colorColor of focused point ring. Can be color string or [r, g, b, a] array
focused_point_indexIndex of focused point (prioritized over focus_point method)
render_linksEnable or disable link rendering
link_colorDefault link color (when link_color_by not specified). Can be color string or [r, g, b, a] array
link_greyout_opacityOpacity of unselected links during selection
link_widthDefault link width (when link_width_by not specified)
link_width_scaleScale factor for link widths
curved_linksEnable or disable curved links
curved_link_segmentsSegments defining curved links
curved_link_weightWeight factor for link curvature
curved_link_control_point_distanceControl point positioning (1 = distance equal to line length)
link_arrowsEnable or disable arrows on links (when link_arrow_by not specified)
link_arrows_size_scaleScale factor for link arrow size
link_visibility_distance_rangePixel distance range for link transparency [min, max]
link_visibility_min_transparencyMinimum transparency of links
scale_points_on_zoomScale point sizes when zooming (default: True)
scale_links_on_zoomScale link widths when zooming
initial_zoom_levelStarting zoom level
disable_zoomEnable or disable zooming
enable_dragAllow graph dragging
fit_view_on_initAutomatically fit view to all points on init
fit_view_delayDelay for fitting view after initialization (ms)
fit_view_paddingPadding around fit view area
fit_view_durationAnimation duration for view fitting (ms)
fit_view_by_points_in_rectFit view to specified rectangle of points [[left, bottom], [right, top]]

Labels

ParameterDescription
show_labelsShow labels (except hovered) on canvas
show_dynamic_labelsShow dynamic labels for visible points
show_top_labelsDisplay labels for top points
show_top_labels_limitMaximum number of top points to show labels for
show_labels_forArray of point IDs to show labels for
static_label_weightWeight of static labels
dynamic_label_weightWeight of dynamic labels
label_marginMargin between label and point
show_hovered_point_labelDisplay label for hovered point (default: True)
show_cluster_labelsDisplay cluster labels
point_label_colorColor for point labels
point_label_font_sizeFont size for point labels
cluster_label_font_sizeFont size for cluster labels
scale_cluster_labelsScale cluster labels
label_paddingPadding around labels as [left, top, right, bottom]
use_point_color_strategy_for_cluster_labelsUse point color strategy for cluster labels
select_cluster_on_label_clickSelect cluster when its label is clicked

Additional Parameters

ParameterDescription
show_fps_monitorDisplay FPS counter in upper right corner
pixel_ratioCanvas pixel ratio
random_seedSeed value for random number generation (can be int or str)
polygonal_selector_stroke_colorColor for polygonal selector stroke
polygonal_selector_line_widthLine width for polygonal selector
select_point_on_clickBehavior when clicking a point (True, False, or 'single')
select_point_on_label_clickBehavior when clicking a point label (True, False, or 'single')
reset_selection_on_empty_canvas_clickReset selection when clicking empty canvas
focus_point_on_clickFocus point when clicked
focus_point_on_label_clickFocus point when its label is clicked
components_display_state_modeControl display state of components ('loading', False, or None)
status_indicator_modeControl status indicator mode ('spinner', 'text', False, or None)
preserve_point_positions_on_data_updatePreserve point positions when data is updated

Legends

ParameterDescription
disable_point_color_legendDisable point color legend
disable_point_size_legendDisable point size legend
disable_link_color_legendDisable link color legend
disable_link_width_legendDisable link width legend

Widget-Specific Parameters

These parameters are specific to the Python widget and control widget behavior or provide access to widget state.

ParameterDescription
api_keyAPI key for exporting projects to Cosmograph platform (can also be set globally with set_api_key())
clicked_point_indexIndex of clicked point (read-only attribute, see Methods and Values)
clicked_point_idID of clicked point (read-only attribute, see Methods and Values)
selected_point_indicesList of selected point indices (read-only attribute, see Methods and Values)
selected_point_idsList of selected point IDs (read-only attribute, see Methods and Values)

Quadtree Algorithm Settings (Experimental)

ParameterDescription
use_quadtreeActivate quadtree algorithm for Many-Body force
simulation_repulsion_quadtree_levelsBarnes–Hut approximation depth (when use_quadtree: True)

To learn about programmatic control methods and attributes, see Methods and Values. For advanced features like partial functions, ingress system, and custom data resolution, see Advanced Features.