Python ASCII 图形绘制

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/834395/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 20:56:51  来源:igfitidea点击:

Python ASCII Graph Drawing

pythongraphascii

提问by Patrick

I'm looking for a library to draw ASCII graphs (for use in a console) with Python. The graph is quite simple: it's only a flow chart for pipelines.

我正在寻找一个库来使用 Python 绘制 ASCII 图形(用于控制台)。该图非常简单:它只是管道的流程图。

I saw NetworkX and igraph, but didn't see a way to output to ascii.

我看到了 NetworkX 和 igraph,但没有看到输出到 ascii 的方法。

Do you have experience in this?

你有这方面的经验吗?

Thanks a lot!

非常感谢!

Patrick

帕特里克

EDIT 1: I actually found a library doing what I need, but it's in perl Graph::Easy. I could call the code from python but I don't like the idea too much... still looking for a python solution :)

编辑 1:我实际上找到了一个库做我需要的,但它在 perl Graph::Easy 中。我可以从 python 调用代码,但我不太喜欢这个想法......仍在寻找 python 解决方案:)

采纳答案by Jon Cage

When you say 'simple network graph in ascii', do you mean something like this?

当您说“ascii 中的简单网络图”时,您的意思是这样的吗?

.===.   .===.   .===.   .===.
| a |---| b |---| c |---| d |
'==='   '==='   '---'   '==='

I suspect there are probably better ways to display whatever information it is that you have than to try and draw it on the console. If it's just a pipeline, why not just print out:

我怀疑可能有更好的方法来显示您拥有的任何信息,而不是尝试在控制台上绘制它。如果它只是一个管道,为什么不直接打印出来:

a-b-c-d

If you're sure this is the route, one thing you could try would be to generate a decent graph using Matplotliband then post the contents to one of the many image-to-ascii convertersyou can find on the web.

如果您确定这是路线,您可以尝试的一件事是使用Matplotlib生成一个像样的图形,然后将内容发布到您可以在网上找到的众多图像到 ASCII 转换器之一

回答by David Wolever

ascii-plottermight do what you want...

ascii-plotter可能会做你想做的......

回答by wr.

It's not directly Python based, but you should take a look into the artist-mode of emacs

它不是直接基于 Python 的,但你应该看看 emacs 的艺术家模式

You can control emacs from python with pymacs, or you can take a look at the lisp code and draw some inspiration.

你可以用pymacs从 python 控制 emacs ,也可以看一下 lisp 代码,从中汲取一些灵感。