使用 python 绘制 svg 图表

发布于 2024-07-14 19:46:47 字数 464 浏览 4 评论 0原文

我正在寻找一个库来在 python 中生成 svg 图(我从 sql 数据库获取数据)。 我找到了 python-gd,但它没有太多文档,上次更新是在 2005 年,所以我想知道是否还有其他库适合此目的。

我主要考虑简单的线图,比如 这个示例折线图

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(11

謸气贵蔟 2024-07-21 19:46:47

尝试使用 matplotlib。 您可以使用 SVG 后端 配置它。

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

世界如花海般美丽 2024-07-21 19:46:47

当您正在寻找简单的线条图形时,可能是 CairoPlot将满足您的需求,因为它可以生成开箱即用的 svg 输出文件。 看看这个

CairoPlot - DotLinePlot

此示例图像仅显示了其部分功能。 使用 launchpad 上提供的主干版本,您将能够添加图例框并添加轴标题。

除此之外,使用主干版本,还可以生成:

  • 点线图(我认为您需要的)
  • 散点图
  • 饼图/圆环图
  • 水平/垂直条形图
  • 甘特图

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
贱人配狗天长地久 2024-07-21 19:46:47

pyCairo 是一个值得关注的选项。

pyCairo is an option worth looking at.

嘴硬脾气大 2024-07-21 19:46:47

PyChart “是一个用于创建高质量封装 Postscript、PDF、PNG 或 <强>SVG图表。”

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

柠檬心 2024-07-21 19:46:47

以下是 Python 中的通用 SVG 库:pySVG

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

瑶笙 2024-07-21 19:46:47

您可以使用 Graphviz 生成 SVG 格式的图表。 有与 Graphviz 的 Python 绑定,例如 pydot —— Graphviz 的 Dot 语言的 Python 接口。

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.

伴我心暖 2024-07-21 19:46:47

考虑 svgwrite https://pypi.org/project/svgwrite,用于创建 SVG 绘图的 Python 包。

Consider svgwrite https://pypi.org/project/svgwrite, a Python package to create SVG drawings.

花海 2024-07-21 19:46:47

svgfig 值得一看:

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

svgfig is worth a look:

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

幼儿园老大 2024-07-21 19:46:47

与 SVG 图并不完全相关,但在搜索相同的内容时,我发现了一个精心收集的有用信息的良好来源来回答您的问题:
http://wiki.python.org/moin/NumericAndScientific/Plotting

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

握住你手 2024-07-21 19:46:47

我尝试整理可用图表库的列表(这是一项正在进行的工作,我不断更新列表):http://blizzardzblogs.blogspot.com/2010/12/data-visualization-charts-and.html

我觉得 protovis 可以为您完成这项工作。 它

  • 重量轻,
  • 生成 svg(可以轻松导出)并且
  • 是 javascript

,所以无需再学习:)

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 :)

彡翼 2024-07-21 19:46:47

2018 更新:

Plotly ( https://github.com/plotly/plotly. py / https://plot.ly/d3 -js-for-python-and-pandas-charts/ )可能是最通用的解决方案。 它是在 MIT 许可证下分发的(免费使用和重用),尽管它包含的功能可能与某些具有更多限制性安全问题的 CMS 不兼容,因为它依赖于 JS,尽管也可以选择将图表导出为纯 SVG。

Pygal ( https://github.com/Kozea/pygal / http://pygal.org )更简单,仅依赖于 svg 标准。 因此,它的结果在更受限制的 CMS 系统下更可重用。 它是在 GNU 许可证下分发的。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文