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.1.tar.gz (3.3 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.1-py3-none-any.whl (3.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: chartspan-0.1.1.tar.gz
  • Upload date:
  • Size: 3.3 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.1.tar.gz
Algorithm Hash digest
SHA256 1a7b06dffcaee9edb5930bf861024df77dcbc88f273adf037dc0ca952d807a7f
MD5 25cd2d50f8b4ee66008271b2e0d486a2
BLAKE2b-256 757eb24f5a59e6053f70baaf42df5b79f4cdae92577b0b8250b56990c7297fc9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: chartspan-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 3.9 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 96dbcc0041071caccfc44a16c2657f4d706b5e2dbb56509f58a69460173fdd27
MD5 c5d0056e0352527af3849328a367cf54
BLAKE2b-256 12f59407ca46c81050d6d0b6cfed4418066bc91588acfa1303dc903c52b559ea

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