开发者

Graphically represent lists

Is there a quick way (without the overhead of using a GUI or graphics module) to visually render 2d and 3d lists.

For example if I have a 2d array of zeros and ones, I would like to draw a black and white grid according to this开发者_开发百科 array.

I am looking for a module that allows me to do these thing in simple ways. Similar to the easiness of that matplotlib allows drawing graphs.


The command matshow in matplotlib displays a matrix:

import pylab as p
p.matshow(p.array([[0,1],[1,1]]),cmap="Greys") ; p.show()

This would work for 2d lists. As for 3d lists, I'm not sure I fully understand how you're planning on visualising them.


Are you looking for something to run on command line? If that is so, you could simply write your own little function in a very few lines. Something like this:

>>> matrix = [[0,1,0],[1,1,1],[0,0,1]]
>>> convert = lambda x : '■ ' if x == 1 else '□ '
>>> for row in matrix:
...     print ''.join([convert(el) for el in row])
... 
□ ■ □ 
■ ■ ■ 
□ □ ■ 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜