Skip to main content
Glama

mpl_mcp_plot_scatter

Create scatter plots to visualize relationships between numerical data points using x and y coordinates. Customize charts with labels, colors, markers, and save options for data analysis.

Instructions

Plots scatter chart of given datavalues

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
x_dataYes
y_dataYes
labelsNo
titleNo
xlabelNo
ylabelNo
colorNoblue
sizeNo
alphaNo
markerNoo
edgecolorsNoface
linewidthsNo
saveNo
dpiNo
figsizeNo
gridNo
legendNo

Implementation Reference

  • The handler function plot_scatter that implements the core logic for creating a customizable scatter plot using matplotlib.pyplot, processes input data into numpy arrays, handles multiple series, customizes appearance, and returns a PNG Image object.
    def plot_scatter(
        x_data: List[Union[float, int]],
        y_data: List[Union[float, int]],
        labels: Optional[Union[str, List[str]]] = None,
        title: str = "",
        xlabel: str = "",
        ylabel: str = "",
        color: Union[str, List[str]] = "blue",
        size: Union[int, float, List[float]] = 36,
        alpha: float = 0.7,
        marker: str = "o",
        edgecolors: Optional[str] = "face",
        linewidths: float = 1.0,
        save: bool = False,
        dpi: int = 200,
        figsize: Optional[List[Union[int, float]]] = None,
        grid: bool = True,
        legend: bool = False,
    ) -> Image:
        """
        Create a scatter plot with customizable appearance.
    
        Args:
            x_data: X-axis data points (1D or 2D sequence for multiple series)
            y_data: Y-axis data points (1D or 2D sequence for multiple series)
            labels: Label or list of labels for the data series
            title: Plot title
            xlabel: Label for the x-axis
            ylabel: Label for the y-axis
            color: Color or list of colors for the markers (default: "blue")
            size: Size or list of sizes for the markers (default: 36)
            alpha: Alpha transparency (0-1, default: 0.7)
            marker: Marker style (default: "o" for circle)
            edgecolors: Color of marker edges (default: "face")
            linewidths: Width of marker edges (default: 1.0)
            save: If True, save the figure to a buffer
            dpi: Output image resolution (dots per inch, default: 200)
            figsize: Figure size as (width, height) in inches
            grid: Whether to show grid lines (default: True)
            legend: Whether to show legend (default: False)
    
        Returns:
            FastMCP Image object with the plotted scatter chart
        """
        # Convert inputs to numpy arrays for processing
        x = np.asarray(x_data, dtype=float)
        y = np.asarray(y_data, dtype=float)
    
        # Ensure y is at least 2D
        if y.ndim == 1:
            y = y.reshape(-1, 1)
    
        # Ensure x is 1D and matches the number of data points in y
        x = np.asarray(x_data, dtype=float).flatten()
        if len(x) != y.shape[0]:
            x = np.tile(x, (y.shape[1], 1)).T.flatten()
            y = y.T.reshape(-1, y.shape[0]).T
    
        # Handle labels — normalize to a list
        if labels is None:
            labels_list: List[str] = [""] * y.shape[1]
        elif isinstance(labels, str):
            labels_list = [labels]
        else:
            labels_list = list(labels)
    
        # Handle colors — normalize to a list
        if isinstance(color, str):
            colors_list = [color] * y.shape[1]
        else:
            colors_list = list(color)
    
        # Handle sizes — normalize to list of floats
        if isinstance(size, (int, float)):
            sizes_list = [float(size)] * y.shape[1]
        elif isinstance(size, (list, tuple, np.ndarray)):
            sizes_list = [float(s) for s in list(size)]
        else:
            sizes_list = [36.0] * y.shape[1]
    
        # Normalize figsize and create figure
        if figsize and len(figsize) >= 2:
            figsize_vals = (float(figsize[0]), float(figsize[1]))
        else:
            figsize_vals = (6.0, 4.0)
    
        fig, ax = plt.subplots(figsize=figsize_vals, dpi=dpi)
    
        # Create the scatter plot for each series
        for i in range(y.shape[1]):
            current_label = labels_list[i] if i < len(labels_list) else f"Series {i+1}"
            current_color = colors_list[i % len(colors_list)]
            current_size = sizes_list[i % len(sizes_list)]
    
            ax.scatter(
                x,
                y[:, i],
                label=current_label,
                c=current_color,
                s=current_size,
                alpha=alpha,
                marker=marker,
                edgecolors=edgecolors,
                linewidths=linewidths,
            )
    
        # Customize the plot
        ax.set_title(title)
        ax.set_xlabel(xlabel)
        ax.set_ylabel(ylabel)
    
        if grid:
            ax.grid(True)
    
        if legend and any(labels_list):
            ax.legend()
    
        # Save to buffer and return
        buf = io.BytesIO()
        fig.savefig(buf, format="png", dpi=dpi, bbox_inches="tight")
        plt.close(fig)
        buf.seek(0)
        return Image(data=buf.read(), format="png")
  • Registers the plot_scatter function as an MCP tool on the mpl_mcp FastMCP server instance with a description.
    mpl_mcp.tool(plot_scatter, description="Plots scatter chart of given datavalues")
  • Imports the plot_scatter handler from core.scatter_chart for registration.
    from .core.scatter_chart import plot_scatter
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden but provides minimal behavioral information. It states what the tool does but doesn't disclose whether it creates visual output, saves files, requires specific data formats, or has any side effects. 'Plots' implies visual generation, but details about output format, display behavior, or file handling are missing.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Extremely concise single sentence with zero wasted words. The description is front-loaded with the core purpose. While it's under-specified, what's present is efficiently structured without redundancy.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a complex tool with 17 parameters, 0% schema description coverage, no annotations, and no output schema, the description is severely inadequate. It identifies the chart type but provides no guidance on parameter usage, output behavior, error conditions, or relationship to sibling tools. The agent would struggle to use this tool effectively.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters1/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate but fails completely. The description mentions 'given datavalues' which vaguely references x_data and y_data parameters, but provides no explanation for any of the 17 parameters, their purposes, relationships, or how they affect the scatter plot. This leaves most parameters semantically undocumented.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Plots scatter chart of given datavalues' - a specific verb ('plots') and resource ('scatter chart'). It distinguishes from some siblings (e.g., mpl_mcp_plot_barchart, mpl_mcp_plot_stack) by specifying scatter chart type, but doesn't fully differentiate from mpl_mcp_plot_chart which could be ambiguous.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance on when to use this tool versus alternatives. The description doesn't mention when scatter plots are appropriate versus other chart types (bar, stack, stem) available in sibling tools, nor does it provide any context about prerequisites or typical use cases.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/abhiphile/fermat-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server