svg diagrams using python

2020-02-17 07:19发布

问题:

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:

回答1:

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.

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


回答2:

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



回答3:

PyChart "is a Python library for creating high quality Encapsulated Postscript, PDF, PNG, or SVG charts."



回答4:

pyCairo is an option worth looking at.



回答5:

Here's a general purpose SVG library in Python: pySVG.



回答6:

You can use Graphviz to generate diagrams in SVG format. There are Python bindings to Graphviz e.g., pydot -- Python interface to Graphviz's Dot language.



回答7:

Consider svgwrite http://packages.python.org/svgwrite/



回答8:

svgfig is worth a look:

http://code.google.com/p/svgfig/



回答9:

Being not exactly related to SVG plots, but searching for the same thing I have found a good source of carefully collected useful info to answer your question: http://wiki.python.org/moin/NumericAndScientific/Plotting



回答10:

I have tried to collate a list of available charting libraries(its an ongoing work, wherein i keep updating the list) : http://blizzardzblogs.blogspot.com/2010/12/data-visualization-charts-and.html

I feel that protovis would do the job for you. Its

  • light weight,
  • generates svg (which can be exported easily) and
  • is javascript

So nothing more to learn :)



回答11:

2018 Update:

Plotly ( https://github.com/plotly/plotly.py / https://plot.ly/d3-js-for-python-and-pandas-charts/ ) is probably the most versatile solution. It is distributed under MIT license (free to use and reuse), although it include features that might not be compatible with some CMS with more restrictive security issues since it relies on JS, although options to export the diagrams as plain SVG are also available.

Pygal ( https://github.com/Kozea/pygal / http://pygal.org ) is simpler relies only on svg standard. As such it's results are more reusable under more restrict CMS systems. It is distributed under GNU license.