Skip to main content

A lightweight Python library for rendering Vega-Lite JSON charts in Jupyter/Colab.

Project description

ChartSpan

ChartSpan is a Python library designed for rendering Vega-Lite JSON specifications directly within Jupyter Notebook or Google Colab. It simplifies the visualization of interactive charts and supports customization for chart dimensions.

Features

  • Inline Rendering: Renders Vega-Lite JSON specifications directly within Jupyter/Colab notebooks.
  • Interactive Charts: Maintains full Vega-Lite interactivity (e.g., zoom, pan, tooltips).
  • Custom Dimensions: Easily adjust chart width and height for different use cases.
  • Lightweight and Easy-to-Use: Minimal setup and dependencies.

Installation

To install ChartSpan, use pip:

pip install chartspan

Usage

Rendering Vega-Lite JSON Charts

Here is an example of how to use ChartSpan to render a Vega-Lite JSON chart:

from chartspan import ChartSpan
import json

# Load Vega-Lite JSON specification
with open("example.json", "r") as f:
    spec = json.load(f)

# Render chart inline
chart = ChartSpan(width=800, height=600)
chart.render_inline(spec)

Customization

You can specify custom dimensions for the chart:

chart = ChartSpan(width=1000, height=800)
chart.render_inline(spec)

This modifies the chart's width and height, ensuring it fits your specific needs.

Example

Save the following Vega-Lite JSON to a file named example.json:

{
  "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
  "mark": "point",
  "data": {
    "values": [
      {"x": 1, "y": 2},
      {"x": 2, "y": 3}
    ]
  },
  "encoding": {
    "x": {"field": "x", "type": "quantitative"},
    "y": {"field": "y", "type": "quantitative"}
  }
}

Run the following Python code:

from chartspan import ChartSpan
import json

with open("example.json", "r") as f:
    spec = json.load(f)

chart = ChartSpan(width=800, height=600)
chart.render_inline(spec)

This will display an interactive scatter plot in your Jupyter Notebook or Colab environment.

Dependencies

  • IPython

Install dependencies using:

pip install IPython

License

ChartSpan is licensed under the MIT License.

Contributing

Contributions are welcome! If you'd like to contribute, please fork the repository and submit a pull request.

Acknowledgments

ChartSpan uses the Vega-Lite and Vega-Embed libraries for rendering charts. Special thanks to the developers of these powerful visualization tools.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

chartspan-0.1.2.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

chartspan-0.1.2-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

Details for the file chartspan-0.1.2.tar.gz.

File metadata

  • Download URL: chartspan-0.1.2.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.6

File hashes

Hashes for chartspan-0.1.2.tar.gz
Algorithm Hash digest
SHA256 520e49738be0a4704261bfac7e5defb5e63802eda3d1b54be25b63f768fb94f2
MD5 e6143d6818884b782a3e1e7aaff706d7
BLAKE2b-256 50b32635b9a8a9ff14e5eacbd319a88b3b598e770f125705cf000065b474456d

See more details on using hashes here.

File details

Details for the file chartspan-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: chartspan-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 4.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.6

File hashes

Hashes for chartspan-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c6c99ccb312b351c03ef067e43735ac38fbd5b05e58d0a464c56181dbed876b9
MD5 a527ca6d12ccb359c2427dd5dda8d845
BLAKE2b-256 ad9fa89293fa9acd0258d86f5a1f5a68215dd7b86de6d32d8c7dd81528cfb917

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page