Skip to main content

plot2llm logo

plot2llm

PyPI License: MIT Python

Convert your Python plots into LLM-ready structured outputs — from matplotlib and seaborn.

Plot2LLM bridges the gap between data visualization and AI. Instantly extract technical summaries, JSON, or LLM-optimized context from your figures for explainable AI, documentation, or RAG pipelines.

🧠 Use the 'semantic' format to generate structured context optimized for GPT, Claude or any RAG pipeline.

Latest Updates (v0.2.1):

  • ✅ Complete Statistical Insights: Full distribution analysis, correlations, outliers, and central tendency for all plot types
  • ✅ Enhanced Plot Type Detection: Improved histogram vs bar vs line detection with proper prioritization
  • ✅ Rich Pattern Analysis: Detailed shape characteristics and pattern recognition for all visualization types
  • ✅ Comprehensive Test Suite: 172/174 tests passing (98.9% success rate) with 24s execution time
  • ✅ Production Ready: All core features validated with extensive error handling and edge case coverage
  • ✅ Code Quality: All linting issues resolved with ruff and black formatting

Features

Feature Status
Matplotlib plots ✅ Full support
Seaborn plots ✅ Full support
JSON/Text/Semantic output ✅
Custom formatters/analyzers ✅
Multi-axes/subplots ✅
Level of detail control ✅
Error handling ✅
Extensible API ✅
Statistical Analysis ✅ Complete
Pattern Analysis ✅ Rich insights
Axis Type Detection ✅ Smart detection
Unicode Support ✅ Full support
Distribution Analysis ✅ Skewness/Kurtosis
Correlation Analysis ✅ Pearson/Spearman
Outlier Detection ✅ IQR method
Plot Type Detection ✅ Histogram/Bar/Line
Plotly/Bokeh/Altair detection 🚧 Planned
Jupyter plugin 🚧 Planned
Export to Markdown/HTML 🚧 Planned
Image-based plot analysis 🚧 Planned

Who is this for?

  • Data Scientists who want to document or explain their plots automatically
  • AI engineers building RAG or explainable pipelines
  • Jupyter Notebook users creating technical visualizations
  • Developers generating automated reports with AI
  • Researchers needing statistical analysis of visualizations

Installation

pip install plot2llm

For full functionality with matplotlib and seaborn:

pip install plot2llm[all]

Note: Version 0.2.2 includes all required dependencies (scipy, jsonschema) for complete functionality.

Or, for local development:

git clone https://github.com/Osc2405/plot2llm.git
cd plot2llm
pip install -e .

Quick Start

import matplotlib.pyplot as plt
import numpy as np
from plot2llm import FigureConverter

x = np.linspace(0, 2 * np.pi, 100)
fig, ax = plt.subplots()
ax.plot(x, np.sin(x), label="sin(x)", color="royalblue")
ax.plot(x, np.cos(x), label="cos(x)", color="orange")
ax.set_title('Sine and Cosine Waves')
ax.set_xlabel('Angle [radians]')
ax.set_ylabel('Value')
ax.legend()

converter = FigureConverter()
text_result = converter.convert(fig, 'text')
print(text_result)

Examples

Basic Usage

import matplotlib.pyplot as plt
from plot2llm import FigureConverter

fig, ax = plt.subplots()
ax.bar(['A', 'B', 'C'], [10, 20, 15], color='skyblue')
ax.set_title('Bar Example')

converter = FigureConverter()
print(converter.convert(fig, 'text'))

Advanced Statistical Analysis

import seaborn as sns
import matplotlib.pyplot as plt
from plot2llm import FigureConverter

# Create a scatter plot with correlation
fig, ax = plt.subplots()
x = np.random.randn(100)
y = 2 * x + np.random.randn(100) * 0.5
ax.scatter(x, y)
ax.set_title('Correlation Analysis')

converter = FigureConverter()
semantic_result = converter.convert(fig, 'semantic')

# Access statistical insights
stats = semantic_result['statistical_insights']
print(f"Correlation: {stats['correlations'][0]['value']:.3f}")
print(f"Strength: {stats['correlations'][0]['strength']}")

Real-World Examples

The examples/ directory contains comprehensive examples:

  • minimal_matplotlib.py: Basic matplotlib usage
  • minimal_seaborn.py: Basic seaborn usage
  • real_world_analysis.py: Financial, marketing, and customer segmentation analysis
  • llm_integration_demo.py: LLM integration and format comparison
  • semantic_output_*.py: Complete semantic output examples

Run any example with:

python examples/minimal_matplotlib.py

Output Formats

Text Format

Plot types in figure: line
Figure type: matplotlib.Figure
Dimensions (inches): [8.0, 6.0]
Title: Demo Plot
Number of axes: 1
...

JSON Format

{
  "figure_type": "matplotlib",
  "title": "Demo Plot",
  "axes": [...],
  ...
}

Semantic Format (LLM-Optimized)

{
  "metadata": {
    "figure_type": "matplotlib",
    "detail_level": "medium"
  },
  "axes": [
    {
      "title": "Demo Plot",
      "plot_types": [{"type": "line"}],
      "x_type": "numeric",
      "y_type": "numeric"
    }
  ],
  "statistical_insights": {
    "central_tendency": {"mean": 0.5, "median": 0.4},
    "correlations": [{"type": "pearson", "value": 0.95, "strength": "strong"}]
  },
  "pattern_analysis": {
    "pattern_type": "trend",
    "shape_characteristics": {
      "monotonicity": "increasing",
      "smoothness": "smooth"
    }
  }
}

Advanced Features

Statistical Analysis

  • Central Tendency: Mean, median, mode calculations
  • Variability: Standard deviation, variance, range analysis
  • Correlations: Pearson correlation coefficients with strength and direction
  • Data Quality: Total points, missing values detection
  • Distribution Analysis: Skewness and kurtosis for histograms

Pattern Analysis

  • Monotonicity: Increasing, decreasing, or mixed trends
  • Smoothness: Smooth, piecewise, or discrete patterns
  • Symmetry: Symmetric or asymmetric distributions
  • Continuity: Continuous or discontinuous data patterns

Smart Axis Detection

  • Numeric Detection: Handles Unicode minus signs and various numeric formats
  • Categorical Detection: Identifies discrete categories vs continuous ranges
  • Mixed Support: Works with both Matplotlib and Seaborn plots

API Reference

See the full API Reference for details on all classes and methods.


Project Status

This project is in stable beta. Core functionalities are production-ready with comprehensive test coverage.

  • Matplotlib support (Full)
  • Seaborn support (Full)
  • Extensible formatters/analyzers
  • Multi-format output (text, json, semantic)
  • Statistical analysis with correlations
  • Pattern analysis with shape characteristics
  • Smart axis type detection
  • Unicode support for numeric labels
  • Comprehensive error handling
  • Plotly/Bokeh/Altair integration
  • Jupyter plugin
  • Export to Markdown/HTML
  • Image-based plot analysis

Changelog

v0.2.1 (Latest)

  • ✅ Enhanced Statistical Analysis: Complete statistical insights for all plot types
  • ✅ Improved Plot Type Detection: Better histogram vs bar vs line detection
  • ✅ Rich Pattern Analysis: Detailed shape characteristics for all visualization types
  • ✅ Comprehensive Test Suite: 172/174 tests passing (98.9% success rate)

v0.2.1

  • ✅ Enhanced Statistical Analysis: Complete statistical insights for all plot types
  • ✅ Improved Plot Type Detection: Better histogram vs bar vs line detection
  • ✅ Rich Pattern Analysis: Detailed shape characteristics for all visualization types
  • ✅ Comprehensive Test Suite: 172/174 tests passing (98.9% success rate)

Contributing

Pull requests and issues are welcome! Please see the docs/ folder for API reference and contribution guidelines.


License

MIT License



Try it, give feedback, or suggest a formatter you'd like to see!

Metadata

Release files for plot2llm 0.2.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for plot2llm 0.2.2
File Size Uploaded Provenance Actions
plot2llm-0.2.2.tar.gz 1.4 MB Without provenance Details for plot2llm-0.2.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for plot2llm 0.2.2
File Interpreter ABI Platform Actions
plot2llm-0.2.2-py3-none-any.whl Python 3 none any Details for plot2llm-0.2.2-py3-none-any.whl

Total release size: 1.5 MB

Release files / plot2llm-0.2.2.tar.gz

Download URL plot2llm-0.2.2.tar.gz
Size 1.4 MB
Tags Source
SHA-256 checksum
How to use checksums
4313754b822d978083c9b7ad1dbf7597aff7222ad63f6bb7f099e07d302c011c
BLAKE2b-256 checksum
How to use checksums
8c02f6f9f19baf2d322317613895a5e34c12d94102a6781fdc7c97f4b2c96887
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.4

Release files / plot2llm-0.2.2-py3-none-any.whl

Download URL plot2llm-0.2.2-py3-none-any.whl
Size 76.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
aa2b8dbf1db01fdf2698d183bda46d755d61c5ce35a1d868a3cac8013835452a
BLAKE2b-256 checksum
How to use checksums
8582fa01391edb3393fbc8023196fd117497b26a786fe30d1c157ef2e6cb508d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.4

Security for plot2llm 0.2.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page