encode_point_size
Encode node sizes in a graph visualization based on a specified column, supporting categorical or continuous mappings. Adjust sizes dynamically for clearer representation of node attributes like 'score' or 'type'.
Instructions
Set node size encoding for a graph using Graphistry's encode_point_size API.
Args:
graph_id (str): The ID of the graph to modify.
column (str): The node column to use for size encoding (e.g., 'score', 'type').
categorical_mapping (dict, optional): Map of category values to sizes. Example: {'mac': 50, 'macbook': 100}. If not provided, Graphistry will auto-assign sizes.
default_mapping (float, optional): Size to use for values not in categorical_mapping. Example: 20.
as_continuous (bool, optional): If True, treat the column as continuous and use a size gradient. Example: True for numeric columns like 'score'.
Returns:
dict: { 'graph_id': ..., 'url': ... } with the updated visualization URL.
Example:
encode_point_size(graph_id, column='score', as_continuous=True)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| categorical_mapping | No | ||
| column | Yes | ||
| default_mapping | No | ||
| graph_id | Yes |
Implementation Reference
- The handler function decorated with @mcp.tool() registers and implements the encode_point_size tool. It modifies a cached Graphistry graph object by encoding node sizes based on a specified column, using optional categorical or default mappings, via the Graphistry encode_point_size method.@mcp.tool() async def encode_point_size( graph_id: str, column: str, categorical_mapping: Optional[dict] = None, default_mapping: Optional[float] = None, ) -> Dict[str, Any]: """ Set node size encoding for a graph using Graphistry's encode_point_size API. Args: graph_id (str): The ID of the graph to modify. column (str): The node column to use for size encoding (e.g., 'score', 'type'). categorical_mapping (dict, optional): Map of category values to sizes. Example: {'mac': 50, 'macbook': 100}. If not provided, Graphistry will auto-assign sizes. default_mapping (float, optional): Size to use for values not in categorical_mapping. Example: 20. as_continuous (bool, optional): If True, treat the column as continuous and use a size gradient. Example: True for numeric columns like 'score'. Returns: dict: { 'graph_id': ..., 'url': ... } with the updated visualization URL. Example: encode_point_size(graph_id, column='score', as_continuous=True) """ if graph_id not in graph_cache: raise ValueError(f"Graph not found: {graph_id}") g = graph_cache[graph_id]["graph"] kwargs = {"column": column} if categorical_mapping: kwargs["categorical_mapping"] = categorical_mapping if default_mapping is not None: kwargs["default_mapping"] = default_mapping g = g.encode_point_size(**kwargs) graph_cache[graph_id]["graph"] = g return {"graph_id": graph_id, "url": g.plot(render=False)}