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 Google Colab. It simplifies the visualization of interactive charts and supports customization for chart dimensions, text color, and background color.

Features

  • Inline Rendering: Renders Vega-Lite JSON specifications directly within Google Colab.
  • Interactive Charts: Maintains full Vega-Lite interactivity (e.g., zoom, pan, tooltips).
  • Custom Dimensions: Easily adjust chart width and height for different use cases.
  • Text Color Customization: Allows specifying custom colors for text elements.
  • Background Color Customization: Supports setting a custom background color for charts.
  • 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)

You can also customize the text color for labels, titles, legends, and axes:

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

Alternatively, you can override the default text color for a specific chart:

chart = ChartSpan(width=800, height=600, text_color="black")
chart.render_inline(spec, text_color="red")

You can also customize the background color of the chart:

chart = ChartSpan(width=800, height=600, text_color="black")
chart.render_inline(spec, background_color="lightgray")

This modifies the chart's width, height, text color, and background color, ensuring it fits your specific needs and visual style.

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, text_color="#dcdfe1")
chart.render_inline(spec, background_color="#353535")

This will display an interactive scatter plot in your Google Colab environment, with labels and titles rendered in green and a light blue background.

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: chartspan-0.1.3.tar.gz
  • Upload date:
  • Size: 3.9 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.3.tar.gz
Algorithm Hash digest
SHA256 31a5fc8c738f119aebd9dad30e80f1ca8dd4352036df0ac1620bc4ef7c56eef6
MD5 af8b4c2791e8ad09c3f51f73080cb278
BLAKE2b-256 96bfdcad56f913ae0b93312b97e646b6de1dabd020f04ca5398d3d0f8350f6d7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: chartspan-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 4.5 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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 5088d5a993e6d0b80ee670f7c4df0967c006395e3ec1f9ff20b50f20a742c231
MD5 536f340be1a975b1ef971ede1fe308e2
BLAKE2b-256 e515f0da07b3f6bb002e4745592970f8507f2554e80064cf347fe4805c5baf83

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