Enables creation of publication-quality statistical graphics using plotnine, Python's implementation of the grammar of graphics, with support for 20+ geometry types, multi-layer plots, theming, faceting, and statistical transformations.
Implements R's ggplot2 grammar of graphics paradigm in Python through plotnine, allowing composition of visualizations using aesthetics, geometries, scales, themes, facets, and coordinate systems.
Plotnine MCP Server
A Model Context Protocol (MCP) server that brings ggplot2's grammar of graphics to Python through plotnine, enabling AI-powered data visualization via natural language.
Create publication-quality statistical graphics through chat using plotnine's Python implementation of R's beloved ggplot2. This modular MCP server allows Claude and other AI assistants to generate highly customizable visualizations by composing layers through the grammar of graphics paradigm.
Features
🎨 Multi-Layer Plots: Combine multiple geometries in a single plot (scatter + trend lines, boxplots + jitter, etc.)
Multiple Data Sources: Load data from files (CSV, JSON, Parquet, Excel), URLs, or inline JSON
Grammar of Graphics: Compose plots using aesthetics, geometries, scales, themes, facets, and coordinates
20+ Geometry Types: Points, lines, bars, histograms, boxplots, violins, and more
Flexible Theming: Built-in themes with extensive customization options
Statistical Transformations: Add smoothing, binning, density estimation, and summaries
Faceting: Split plots by categorical variables using wrap or grid layouts
Multiple Output Formats: PNG, PDF, SVG with configurable dimensions and DPI
Installation
1. Clone or download this repository
2. Install dependencies
Using pip:
For full functionality (parquet and Excel support):
3. Configure Your MCP Client
Claude Desktop
Add the server to your Claude Desktop configuration file:
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Windows: %APPDATA%\Claude\claude_desktop_config.json
If you installed in a virtual environment, use the full path to python:
Cursor
Add to your Cursor settings by opening the command palette (Cmd/Ctrl+Shift+P) and searching for "Preferences: Open User Settings (JSON)". Add:
Or configure via .cursor/mcp.json in your project:
VSCode (with Cline/Roo-Cline)
Add to your VSCode MCP settings file:
macOS/Linux: ~/.config/Code/User/globalStorage/rooveterinaryinc.roo-cline/settings/cline_mcp_settings.json
Windows: %APPDATA%\Code\User\globalStorage\rooveterinaryinc.roo-cline\settings\cline_mcp_settings.json
For other MCP clients in VSCode, consult their specific documentation for MCP server configuration.
4. Restart Your Application
Restart Claude Desktop, Cursor, or VSCode for the changes to take effect. The plotnine MCP server should now be available!
Usage
Basic Example
Advanced Example
Available Tools
create_plot
Create a plotnine visualization with full customization.
Required Parameters:
data_source: Data source configurationtype: "file", "url", or "inline"path: File path or URL (for file/url types)data: Array of objects (for inline type)format: "csv", "json", "parquet", or "excel" (auto-detected)
aes: Aesthetic mappings (column names)x,y: Axis variablescolor,fill: Color aestheticssize,alpha,shape,linetype: Additional aestheticsgroup: Grouping variable
geom: Geometry specificationtype: Geometry type (point, line, bar, etc.)params: Additional parameters (size, alpha, color, etc.)
Optional Parameters:
scales: Array of scale configurationstheme: Theme configuration with base and customizationsfacets: Faceting configurationlabels: Plot labels (title, x, y, caption, subtitle)coords: Coordinate system configurationstats: Statistical transformationsoutput: Output configuration (format, size, DPI, directory)
list_geom_types
List all available geometry types with descriptions.
Geometry Types
point: Scatter plot points
line: Line plot connecting points
bar: Bar chart (counts by default)
col: Column chart (identity stat)
histogram: Histogram of continuous data
boxplot: Box and whisker plot
violin: Violin plot for distributions
area: Filled area under line
density: Kernel density plot
smooth: Smoothed conditional means
jitter: Jittered points (reduces overplotting)
tile: Heatmap/tile plot
text: Text annotations
errorbar: Error bars
hline/vline/abline: Reference lines
path: Path connecting points in order
polygon: Filled polygon
ribbon: Ribbon for intervals
Examples
Simple Scatter Plot
Line Plot with Theme
Faceted Boxplot
Multi-Layer Plot: Scatter + Smooth Trend
NEW! Layer multiple geometries to create complex visualizations:
Boxplot with Jittered Points
Show both distribution summary and individual data points:
Chat Examples
You can create plots through natural language:
"Create a histogram of the 'age' column from users.csv"
"Make a scatter plot with smooth trend line showing price vs size, colored by category"
"Plot a line chart from sales.csv with date on x-axis and revenue on y-axis, faceted by region, using a dark theme"
"Create a violin plot comparing distributions of test scores across different schools"
"Make a boxplot with individual points overlaid showing temperature by season"
"Create a scatter plot with a linear trend line for each category, showing the relationship between hours studied and test scores"
Configuration Options
Themes
Available base themes:
gray(default)bw(black and white)minimalclassicdarklightvoid
Scale Types
Positional: continuous, discrete, log10, sqrt, datetime
Color/Fill: gradient, discrete, brewer
Coordinate Systems
cartesian(default)flip(swap x and y)fixed(fixed aspect ratio)trans(transformed coordinates)
Output
By default, plots are saved to ./output directory as PNG files with 300 DPI. You can customize:
format: png, pdf, svg
filename: Custom filename (auto-generated by default)
width/height: Dimensions in inches
dpi: Resolution for raster formats
directory: Output directory path
Troubleshooting
"Module not found" errors
Ensure you've installed the package:
Parquet/Excel support
Install optional dependencies:
"Cannot find data file"
Use absolute paths or paths relative to where Claude Desktop is running.
Plot not rendering
Check that:
Column names in
aesmatch your dataData types are appropriate for the geometry
Required aesthetics are provided (e.g.,
xandyfor most geoms)
Development
Running tests
Code formatting
License
MIT
Contributing
Contributions welcome! Please open an issue or submit a pull request.
Resources
hybrid server
The server is able to function both locally and remotely, depending on the configuration or use case.
Enables creation of publication-quality statistical graphics using plotnine's grammar of graphics through natural language, supporting 20+ geometry types, multi-layer plots, and flexible theming for data visualization.