encode_point_color
Set node colors in a graph visualization based on column values, using categorical mapping or continuous gradients to highlight patterns in network data.
Instructions
Set node color encoding for a graph using Graphistry's encode_point_color API.
Args:
graph_id (str): The ID of the graph to modify (from visualize_graph).
column (str): The node column to use for color encoding (e.g., 'type', 'score').
categorical_mapping (dict, optional): Map of category values to color codes. Example: {'mac': '#F99', 'macbook': '#99F'}. If not provided, Graphistry will auto-assign colors.
default_mapping (str, optional): Color code to use for values not in categorical_mapping. Example: 'silver'.
as_continuous (bool, optional): If True, treat the column as continuous and use a gradient palette. Example: True for numeric columns like 'score'.
Returns:
dict: { 'graph_id': ..., 'url': ... } with the updated visualization URL.
Example:
encode_point_color(graph_id, column='type', categorical_mapping={'mac': '#F99', 'macbook': '#99F'}, default_mapping='silver')
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| graph_id | Yes | ||
| column | Yes | ||
| categorical_mapping | No | ||
| default_mapping | No | ||
| as_continuous | No |
Implementation Reference
- The main handler function for the 'encode_point_color' tool, decorated with @mcp.tool() for registration in the FastMCP server. It modifies the graph's node colors based on a specified column and mappings using Graphistry's encode_point_color method.@mcp.tool() async def encode_point_color( graph_id: str, column: str, categorical_mapping: Optional[dict] = None, default_mapping: Optional[str] = None, as_continuous: Optional[bool] = False ) -> Dict[str, Any]: """ Set node color encoding for a graph using Graphistry's encode_point_color API. Args: graph_id (str): The ID of the graph to modify (from visualize_graph). column (str): The node column to use for color encoding (e.g., 'type', 'score'). categorical_mapping (dict, optional): Map of category values to color codes. Example: {'mac': '#F99', 'macbook': '#99F'}. If not provided, Graphistry will auto-assign colors. default_mapping (str, optional): Color code to use for values not in categorical_mapping. Example: 'silver'. as_continuous (bool, optional): If True, treat the column as continuous and use a gradient palette. Example: True for numeric columns like 'score'. Returns: dict: { 'graph_id': ..., 'url': ... } with the updated visualization URL. Example: encode_point_color(graph_id, column='type', categorical_mapping={'mac': '#F99', 'macbook': '#99F'}, default_mapping='silver') """ 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: kwargs["default_mapping"] = default_mapping if as_continuous: kwargs["as_continuous"] = as_continuous g = g.encode_point_color(**kwargs) graph_cache[graph_id]["graph"] = g return {"graph_id": graph_id, "url": g.plot(render=False)}