Skip to main content

Creates svg based charts in python

Project description

A Python package for creating and rendering SVG charts, including line charts, axes, legends, and text labels. This package supports both simple and complex chart structures and is highly customizable for various types of visualizations.

Why did I make this project

Many charting libraries rely on JavaScript-driven client-side rendering, often requiring an intermediate canvas before producing a polished visual. This package takes a different approach: it generates clean, standalone SVG charts entirely within Python. By leveraging SVG’s inherent scalability and styling flexibility, it eliminates the need for JavaScript dependencies, client-side rendering, or post-processing steps. The result is a lightweight, backend-friendly solution for producing high-quality, resolution-independent charts without sacrificing control or maintainability.

While many popular Python charting libraries focus on image-based rendering, and those that support SVG output often produce cumbersome, hard-to-customize files, this library is built with customization at its core. Every chart element is designed to be easily modified, giving developers precise control over appearance and structure.

Features

  • Modular Structure: Create SVG charts with reusable components like Line, Text, Axis, and Shape.

  • Axis Scaling: Automatically generates axis tick values based on the data range with customizable limits.

  • Customizable Styles: Supports custom styles for lines, text, and axes.

  • Legends: Add legends to your charts to represent different data series.

  • Dynamic Rendering: Render a chart in SVG format with full control over size, style, and elements.

  • Support for Simple and Advanced Charts: Create simple line charts or extend the functionality for more complex visualizations.

Installation

pip install pysvgchart

Alternatively, you can clone this repository and install it locally:

git clone https://github.com/arowley-ai/py-svg-chart.git
cd py-svg-chart
pip install .

Usage

Create a simple line chart with the following code:

import pysvgchart as psc

# Sample data
x_values = [0, 1, 2, 3, 4, 5]
y_values = [[0, 2, 4, 6, 8, 10], [0, 1, 2, 3, 4, 5]]

# Create the chart
chart = psc.SimpleLineChart(x_values, y_values, y_names=["Series 1", "Series 2"])

# Add a legend
chart.add_legend(x_position=500, y_position=60, element_x=100, element_y=0, line_length=20, line_text_gap=5)

chart.series[0].styles['stroke'] = 'red'
chart.series[1].styles['stroke'] = 'blue'
chart.x_axis.axis_line.styles['stroke'] = 'black'

# Render the chart as an SVG string
svg_output = chart.render

# Save the SVG output to a file
with open("chart.svg", "w") as f:
    f.write(svg_output)

Extensible Configuration

The entire codebase is designed to be extensible to enable unlimited customisation. All of the lower level elements are accessible via properties of the charts.

Contributing

We welcome contributions! If you’d like to contribute to the project, please follow these steps:

  • Fork this repository.

  • Optionally, create a new branch (eg. git checkout -b feature-branch).

  • Commit your changes (git commit -am ‘Add feature’).

  • Push to the branch (eg. git push origin feature-branch).

  • Open a pull request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

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

pysvgchart-0.0.9.tar.gz (12.1 kB view details)

Uploaded Source

Built Distribution

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

pysvgchart-0.0.9-py2.py3-none-any.whl (9.0 kB view details)

Uploaded Python 2Python 3

File details

Details for the file pysvgchart-0.0.9.tar.gz.

File metadata

  • Download URL: pysvgchart-0.0.9.tar.gz
  • Upload date:
  • Size: 12.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.21

File hashes

Hashes for pysvgchart-0.0.9.tar.gz
Algorithm Hash digest
SHA256 06cd2c63fe571005c82e924a080e88ec19df3a8325eadfb1e399616225ea4be7
MD5 d7a153d379692f7b2303630ad7e8a771
BLAKE2b-256 77fd39dc1b4b1a4e863d1f46b779aaed38d05cc659edaf907e3cfa3204fbb1b3

See more details on using hashes here.

File details

Details for the file pysvgchart-0.0.9-py2.py3-none-any.whl.

File metadata

  • Download URL: pysvgchart-0.0.9-py2.py3-none-any.whl
  • Upload date:
  • Size: 9.0 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.21

File hashes

Hashes for pysvgchart-0.0.9-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 849f3b7723be814eca08c5fb02f3384824f4643af9d0e4908dae39c7d8768e31
MD5 e579eff6884e95db7fc9c1fe354aca38
BLAKE2b-256 2e13b8ae1aa13b6183d7ef6f5e46c37a9e68fc97b4b98d36e4afdc3dcd45c61d

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