Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

svg diagrams using python

Tags:

I am looking for a library to generate svg diagrams in python (I fetch data from a sql database). I have found python-gd, but it has not much documentation and last update was in 2005 so I wonder if there are any other libraries that are good for this purpose.

I am mostly thinking about simple line graphs, something like this: example line graph

like image 925
Zitrax Avatar asked Mar 11 '09 15:03

Zitrax


People also ask

Does Python support SVG?

ReportLab has native support for generating SVGs, but not for embedding SVGs in their PDFs. Fortunately, Dinu Gherman created the svglib package, a pure-Python package that can read SVG files and convert them to other formats that ReportLab can use.

Which Python module is used for SVG?

Svglib is a pure-Python library for reading SVG files and converting them (to a reasonable degree) to other formats using the ReportLab Open Source toolkit.

What is Pygal in Python?

Pygal is a Python module that creates SVG (Scalable Vector Graphics) graphs/charts in a variety of styles. Pygal is highly customize-able, yet also extremely simplistic, which is a very rare combination. You can make line graphs, bar graphs, histograms, pie charts, maps, and a whole lot more.


2 Answers

Try using matplotlib. You can configure it with a SVG backend.

like image 143
zweiterlinde Avatar answered Sep 21 '22 16:09

zweiterlinde


As you're looking for simple line graphics, probably, CairoPlot will fit your needs as it can generate svg output files out of the box. Take a look at this.

CairoPlot - DotLinePlot

This example image shows only a few of its capabilities. Using the trunk version available at launchpad you'll be able to add a legend box and add axis titles.

Besides that, using the trunk version, it's possible to generate:

  • DotLine charts (the ones I believe you need)
  • Scatter charts
  • Pie/Donut charts
  • Horizontal/Vertical Bar charts
  • Gantt charts
like image 44
Rodrigo Avatar answered Sep 18 '22 16:09

Rodrigo