Skip to main content
Glama

create_distribution_plots

Generate distribution plots for numeric data columns to visualize patterns and outliers using histograms, box plots, violin plots, or KDE plots.

Instructions

Create distribution plots for numeric columns.

Args: file_path: Path to the data file output_path: Path where to save the distribution plots columns: Optional list of specific columns to plot (if None, uses all numeric columns) plot_type: Type of distribution plot (histogram, box, violin, kde)

Returns: Information about the created distribution plots

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
file_pathYes
output_pathYes
columnsNo
plot_typeNohistogram

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • Main handler function that creates distribution plots (histogram, box, violin, or kde) for numeric columns in a dataset. Loads data, filters to numeric columns, creates subplot grid based on column count, generates plots using matplotlib/seaborn, and saves to output path.
    @mcp.tool()
    def create_distribution_plots(file_path: str, output_path: str, 
                                columns: Optional[List[str]] = None,
                                plot_type: str = "histogram") -> str:
        """
        Create distribution plots for numeric columns.
        
        Args:
            file_path: Path to the data file
            output_path: Path where to save the distribution plots
            columns: Optional list of specific columns to plot (if None, uses all numeric columns)
            plot_type: Type of distribution plot (histogram, box, violin, kde)
        
        Returns:
            Information about the created distribution plots
        """
        try:
            if not VISUALIZATION_AVAILABLE:
                return f"Error: {VISUALIZATION_ERROR}"
                
            import pandas as pd
            from pathlib import Path
            import math
            
            # Load the data
            file_extension = Path(file_path).suffix.lower()
            if file_extension == '.csv':
                df = pd.read_csv(file_path)
            elif file_extension == '.json':
                df = pd.read_json(file_path)
            elif file_extension in ['.xlsx', '.xls']:
                df = pd.read_excel(file_path)
            elif file_extension == '.tsv':
                df = pd.read_csv(file_path, sep='\t')
            else:
                df = pd.read_csv(file_path)
            
            # Select numeric columns
            if columns:
                missing_cols = [col for col in columns if col not in df.columns]
                if missing_cols:
                    return f"Error: Columns not found: {missing_cols}"
                numeric_df = df[columns].select_dtypes(include=['number'])
            else:
                numeric_df = df.select_dtypes(include=['number'])
            
            if numeric_df.empty:
                return "Error: No numeric columns found for distribution analysis"
            
            # Calculate subplot dimensions
            n_cols = len(numeric_df.columns)
            if n_cols <= 4:
                n_rows, n_plot_cols = 1, n_cols
            else:
                n_plot_cols = 3
                n_rows = math.ceil(n_cols / n_plot_cols)
            
            # Create subplots
            fig, axes = plt.subplots(n_rows, n_plot_cols, figsize=(5*n_plot_cols, 4*n_rows))
            if n_cols == 1:
                axes = [axes]
            elif n_rows == 1:
                axes = axes if n_cols > 1 else [axes]
            else:
                axes = axes.flatten()
            
            # Create distribution plots
            for i, column in enumerate(numeric_df.columns):
                ax = axes[i] if n_cols > 1 else axes[0]
                
                if plot_type == "histogram":
                    ax.hist(numeric_df[column].dropna(), bins=20, alpha=0.7, edgecolor='black')
                    ax.set_ylabel('Frequency')
                elif plot_type == "box":
                    ax.boxplot(numeric_df[column].dropna())
                    ax.set_ylabel('Value')
                elif plot_type == "violin":
                    sns.violinplot(y=numeric_df[column].dropna(), ax=ax)
                elif plot_type == "kde":
                    sns.kdeplot(data=numeric_df[column].dropna(), ax=ax)
                    ax.set_ylabel('Density')
                else:
                    return f"Error: Unsupported plot type '{plot_type}'. Use: histogram, box, violin, kde"
                
                ax.set_title(f'{plot_type.title()} of {column}')
                ax.set_xlabel(column.replace('_', ' ').title())
                ax.grid(True, alpha=0.3)
            
            # Hide empty subplots
            for i in range(n_cols, len(axes)):
                axes[i].set_visible(False)
            
            plt.tight_layout()
            plt.savefig(output_path, dpi=300, bbox_inches='tight')
            plt.close()
            
            result = {
                "distribution_plots_created": True,
                "plot_type": plot_type,
                "columns_plotted": list(numeric_df.columns),
                "total_plots": len(numeric_df.columns),
                "output_file": output_path,
                "file_size": Path(output_path).stat().st_size if Path(output_path).exists() else 0
            }
            
            return json.dumps(result, indent=2)
            
        except Exception as e:
            return f"Error creating distribution plots: {str(e)}\n{traceback.format_exc()}"
  • Tool registration using @mcp.tool() decorator that exposes the create_distribution_plots function as an MCP tool.
    @mcp.tool()
Behavior2/5

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

No annotations are provided, so the description carries full burden. It mentions creating and saving plots but lacks critical behavioral details: permission requirements for file paths, whether it overwrites existing files, performance considerations for large datasets, or error handling. The description is minimal and doesn't compensate for the absence of annotations.

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

Conciseness4/5

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

The description is well-structured and appropriately sized, with a clear purpose statement followed by parameter and return sections. Each sentence adds value, though the parameter explanations could be more detailed. There's no unnecessary repetition or fluff, making it efficient for an agent to parse.

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

Completeness3/5

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

Given no annotations, 0% schema coverage, and an output schema present, the description is moderately complete. It covers the basic purpose and parameters but lacks behavioral context (e.g., file handling, errors) and doesn't leverage the output schema to explain return values. For a tool with 4 parameters and file operations, more detail is needed for full adequacy.

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

Parameters3/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. It lists all four parameters with brief explanations (e.g., 'Optional list of specific columns to plot'), adding some meaning beyond the schema's titles. However, it doesn't detail parameter constraints (e.g., file formats for 'file_path', valid 'plot_type' options beyond those listed), leaving gaps in documentation.

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: 'Create distribution plots for numeric columns.' It specifies the verb ('create'), resource ('distribution plots'), and target ('numeric columns'). However, it doesn't explicitly differentiate from sibling tools like 'create_correlation_heatmap' or 'create_graph' that also create visualizations, which prevents a perfect score.

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?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention sibling tools like 'create_correlation_heatmap' for relationships or 'get_column_stats' for statistical summaries, nor does it specify prerequisites (e.g., requiring numeric data). Usage is implied but not explicitly defined.

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/moeloubani/visidata-mcp'

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