如何在Mac上使用Python中的点绘制自动图形?

时间:2023-02-02 07:43:17

I am producing graphs in a Python program, and now I need to visualize them.

我在Python程序中生成图形,现在我需要将它们可视化。

I am using Tkinter as GUI to visualize all the other data, and I would like to have a small subwindow inside with the graph of the data. At the moment I have the data being represented in a .dot file. And then I keep graphviz open, which shows the graph. But this is of course suboptimal. I need to get the graph inside the tk window.

我使用Tkinter作为GUI来可视化所有其他数据,我想在内部有一个小子窗口,其中包含数据图。目前,我将数据表示在.dot文件中。然后我保持graphviz打开,显示图表。但这当然不是最理想的。我需要在tk窗口中获取图形。

I thought about using graphviz from the command line, but I always run into the same well known bug:

我想过从命令行使用graphviz,但我总是遇到同样众所周知的错误:

Desktop ibook$ dot -Tpng -O 1.dot
dyld: lazy symbol binding failed: Symbol not found: _pixman_image_create_bits
  Referenced from: /usr/local/lib/graphviz/libgvplugin_pango.5.dylib
  Expected in: flat namespace

dyld: Symbol not found: _pixman_image_create_bits
  Referenced from: /usr/local/lib/graphviz/libgvplugin_pango.5.dylib
  Expected in: flat namespace

Trace/BPT trap

The bug seem to be well known in the Graphviz community:

这个bug似乎在Graphviz社区中众所周知:

http://www.graphviz.org/bugs/b1479.html

http://www.graphviz.org/bugs/b1488.html

http://www.graphviz.org/bugs/b1498.html

So since it seems that I cannot use the command line utility I was wondering if anyone knew a direct way to draw a dot graph in Python, without using the command line, or doing something that would incur the same error?

因为我似乎无法使用命令行实用程序,我想知道是否有人知道在Python中绘制点图的直接方法,不使用命令行,或做一些会导致相同错误的事情?

I am programming on a Mac Leopard, python 2.5.2

我在Mac Leopard上编程,python 2.5.2

2 个解决方案

#1


I do not have a mac to test it on, but the NetworkX package includes methods to read .dot files and draw graphs using matplotlib. You can embed a matplotlib figure in Tk (example 1, example 2).

我没有测试它的mac,但NetworkX包中包含读取.dot文件和使用matplotlib绘制图形的方法。您可以在Tk中嵌入matplotlib图形(示例1,示例2)。

#2


Quick Google pulls up http://code.google.com/p/pydot/. I haven't tried it but it looks promising.

快速谷歌推出了http://code.google.com/p/pydot/。我没试过,但看起来很有希望。

#1


I do not have a mac to test it on, but the NetworkX package includes methods to read .dot files and draw graphs using matplotlib. You can embed a matplotlib figure in Tk (example 1, example 2).

我没有测试它的mac,但NetworkX包中包含读取.dot文件和使用matplotlib绘制图形的方法。您可以在Tk中嵌入matplotlib图形(示例1,示例2)。

#2


Quick Google pulls up http://code.google.com/p/pydot/. I haven't tried it but it looks promising.

快速谷歌推出了http://code.google.com/p/pydot/。我没试过,但看起来很有希望。